bobber6467 / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

nose and doctest disagree on meaning of "__test__" module globals #171

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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

Original issue reported on code.google.com by j...@pobox.com on 19 Mar 2008 at 12:10

GoogleCodeExporter commented 8 years ago

Original comment by j...@pobox.com on 23 Mar 2008 at 2:12