diff options
author | Matthew Brett <matthew.brett@gmail.com> | 2013-03-28 15:51:50 -0700 |
---|---|---|
committer | John Szakmeister <john@szakmeister.net> | 2013-04-15 04:59:26 -0400 |
commit | d130b78af07a606628003bcb2931ed7f55dcb7d0 (patch) | |
tree | a4c39cb744d6624a5425850e42a148e085ff90d9 /unit_tests | |
parent | e9c3e8e1be4793945c4916354917b0e9ac4ff348 (diff) | |
download | nose-d130b78af07a606628003bcb2931ed7f55dcb7d0.tar.gz |
Fix #447: doctests fail when getpackage() returns None
When loading tests from a compiled extension, the result of
`getpackage(filename)` can be None, causing an error in
`DocTestCase.id()` when it tries to use the result as a string. To fix
this, let's return the name of the doctest itself just like an
alternate path in `DocTestCase.id()`.
Diffstat (limited to 'unit_tests')
-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 |
4 files changed, 53 insertions, 0 deletions
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() |