Message184450
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. |
|
Date |
User |
Action |
Args |
2013-03-18 12:15:30 | Claudiu.Popa | set | recipients:
+ Claudiu.Popa |
2013-03-18 12:15:30 | Claudiu.Popa | set | messageid: <1363608930.16.0.788491274205.issue17457@psf.upfronthosting.co.za> |
2013-03-18 12:15:30 | Claudiu.Popa | link | issue17457 messages |
2013-03-18 12:15:29 | Claudiu.Popa | create | |
|