diff options
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | nose/plugins/doctests.py | 2 | ||||
-rw-r--r-- | unit_tests/support/doctest/.gitignore | 1 | ||||
-rw-r--r-- | unit_tests/support/doctest/noname_wrapped.not_py | 6 | ||||
-rw-r--r-- | unit_tests/support/doctest/noname_wrapper.py | 12 | ||||
-rw-r--r-- | unit_tests/test_doctest_no_name.py | 34 |
6 files changed, 57 insertions, 0 deletions
@@ -2,6 +2,8 @@ In Development - Corrected a reference to the multiprocessing plugin in the documentation. Patch by Nick Loadholtes. +- Fixed #447: doctests fail when getpackage() returns None + Patch by Matthew Brett. 1.3.0 diff --git a/nose/plugins/doctests.py b/nose/plugins/doctests.py index 23772d6..c561a47 100644 --- a/nose/plugins/doctests.py +++ b/nose/plugins/doctests.py @@ -387,6 +387,8 @@ class DocTestCase(doctest.DocTestCase): filename = self._dt_test.filename if filename is not None: pk = getpackage(filename) + if pk is None: + return name if not name.startswith(pk): name = "%s.%s" % (pk, name) return name diff --git a/unit_tests/support/doctest/.gitignore b/unit_tests/support/doctest/.gitignore new file mode 100644 index 0000000..c34ef94 --- /dev/null +++ b/unit_tests/support/doctest/.gitignore @@ -0,0 +1 @@ +noname_wrapped.not_pyc diff --git a/unit_tests/support/doctest/noname_wrapped.not_py b/unit_tests/support/doctest/noname_wrapped.not_py new file mode 100644 index 0000000..b1ef784 --- /dev/null +++ b/unit_tests/support/doctest/noname_wrapped.not_py @@ -0,0 +1,6 @@ +def func(): + """ Func + + >>> True + True + """ diff --git a/unit_tests/support/doctest/noname_wrapper.py b/unit_tests/support/doctest/noname_wrapper.py new file mode 100644 index 0000000..32c0bc5 --- /dev/null +++ b/unit_tests/support/doctest/noname_wrapper.py @@ -0,0 +1,12 @@ +def __bootstrap__(): + """ Import the code in ``noname_wrapped.not_py`` in file as our own name + + This is a simplified version of the wrapper that setuptools writes for + dynamic libraries when installing. + """ + import os + import imp + here = os.path.join(os.path.dirname(__file__)) + imp.load_source(__name__, os.path.join(here, 'noname_wrapped.not_py')) + +__bootstrap__() diff --git a/unit_tests/test_doctest_no_name.py b/unit_tests/test_doctest_no_name.py new file mode 100644 index 0000000..a2330a0 --- /dev/null +++ b/unit_tests/test_doctest_no_name.py @@ -0,0 +1,34 @@ +import os +import sys +import unittest +from nose.config import Config +from nose.plugins import doctests +from mock import Bucket + +class TestDoctestErrorHandling(unittest.TestCase): + + def setUp(self): + self._path = sys.path[:] + here = os.path.dirname(__file__) + testdir = os.path.join(here, 'support', 'doctest') + sys.path.insert(0, testdir) + p = doctests.Doctest() + p.can_configure = True + p.configure(Bucket(), Config()) + self.p = p + + def tearDown(self): + sys.path = self._path[:] + + def test_no_name(self): + p = self.p + mod = __import__('noname_wrapper') + loaded = [ t for t in p.loadTestsFromModule(mod) ] + assert len(loaded) == 1, 'Need 1 test suite from noname_wrapper' + found_tests = list(loaded[0]) + assert len(found_tests) == 1, 'Need 1 test from noname_wrapper suite' + assert found_tests[0].id() == 'noname_wrapper.func' + + +if __name__ == '__main__': + unittest.main() |