nose-devs/nose — Issue #260: nose and doctest disagree on meaning of "__test__" module globals
Author: jpellerin
Created: 2011-12-14 16:05:49+00:00
State: open

What steps will reproduce the problem?

$ mkdir bug && cd bug
$ cat > testme.py <<"EOF"
__test__ = False

"""This module is not a test module, so doctests SHOULD be run.

>>> True
True

"""
EOF
$ nosetests --with-doctest

What is the expected output? What do you see instead?

Expected:

.
----------------------------------------------------------------------
Ran 1 test in 0.019s

OK

Got:

----------------------------------------------------------------------
Ran 0 tests in 0.005s

OK

Please use labels and text to provide additional information.

Because the False value causes an AttributeError deep inside module
doctest, I guess the only way to fix this bug is to edit dtcompat.py, if
that's always used in favour of doctest. Or if that's not always used,
reimplement doctest.DocTestFinder,

The same thing happens if __test__ is an empty dict, but for a different
reason: In this case, nose fails to conclude that the module is not a test
module, because the selector logic for finding whether a module is a test
module is duplicated in the plugin, but it's duplicated incompletely, so
__test__ is ignored in that part of the plugin's logic. Possibly a related
issue to consider here is that nose.loader.TestLoader.loadTestsFromModule()
is rather quirky, apparently as a hack to make it possible to write plugin
doctests (for example, it's the only .loadTestsFrom*() method that calls
the corresponding .want*() method on the same object that was passed to the
.loadTestsFrom*() method).

The bigger issue is that nose uses the same module-global name as doctest
to mean a different thing. This means that nose cannot support doctest's
__test__ convention, because any non-empty __test__ dict should cause nose
to conclude that the module is a test module, so doctests should NOT be
run. Maybe use of "__test__" should be deprecated at some point in favour
of a different module global name. Strictly, that name should not be of
the form "__*__" because those names are reserved by Python:

http://docs.python.org/ref/id-classes.html

Google Code Info:
Issue #: 171
Author: j...@pobox.com
Created On: 2008-03-19T00:10:03.000Z
Closed On: