homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Claudiu.Popa
Recipients Claudiu.Popa
Date 2013年03月18日.12:15:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1363608930.16.0.788491274205.issue17457@psf.upfronthosting.co.za>
In-reply-to
Content
There is a problem with unittest discovering and namespace packages. Given the following folder structure, where a namespace package X lies, the following command fails with the following error:
-testbug
 - flufl (namespace package with some tests in it, importable with __import__)
 - test_a.py
 - test_b.py
C:\>py -3 -m unittest discover flufl
Traceback (most recent call last):
 File "C:\Python33\lib\runpy.py", line 160, in _run_module_as_main
 "__main__", fname, loader, pkg_name)
 File "C:\Python33\lib\runpy.py", line 73, in _run_code
 exec(code, run_globals)
 File "C:\Python33\lib\unittest\__main__.py", line 12, in <module>
 main(module=None)
 File "C:\Python33\lib\unittest\main.py", line 124, in __init__
 self.parseArgs(argv)
 File "C:\Python33\lib\unittest\main.py", line 144, in parseArgs
 self._do_discovery(argv[2:])
 File "C:\Python33\lib\unittest\main.py", line 242, in _do_discovery
 self.test = loader.discover(start_dir, pattern, top_level_dir)
 File "C:\Python33\lib\unittest\loader.py", line 205, in discover
 start_dir = os.path.abspath(os.path.dirname((the_module.__file__)))
AttributeError: 'module' object has no attribute '__file__'
This happens because TestLoader.discover assumes that the given dotted package name has the attribute __file__, which seems to not be true in the case of namespace packages. The same error occurs when giving to `discover` a builtin module.
The attached patch tries naively to solve this issue, but it assume in TestLoader._find_tests that it should iterate over all subfolders (the commented line from the patch), unlike the previous way of checking the presence of __init__.py file.
Thanks in advance for your response.
History
Date User Action Args
2013年03月18日 12:15:30Claudiu.Popasetrecipients: + Claudiu.Popa
2013年03月18日 12:15:30Claudiu.Popasetmessageid: <1363608930.16.0.788491274205.issue17457@psf.upfronthosting.co.za>
2013年03月18日 12:15:30Claudiu.Popalinkissue17457 messages
2013年03月18日 12:15:29Claudiu.Popacreate

AltStyle によって変換されたページ (->オリジナル) /