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 <>
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:

   - flufl (namespace package with some tests in it, importable with __import__)

C:\>py -3 -m unittest discover flufl
Traceback (most recent call last):
  File "C:\Python33\lib\", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python33\lib\", line 73, in _run_code
    exec(code, run_globals)
  File "C:\Python33\lib\unittest\", line 12, in <module>
  File "C:\Python33\lib\unittest\", line 124, in __init__
  File "C:\Python33\lib\unittest\", line 144, in parseArgs
  File "C:\Python33\lib\unittest\", line 242, in _do_discovery
    self.test =, pattern, top_level_dir)
  File "C:\Python33\lib\unittest\", 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 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 file.
Thanks in advance for your response.
Date User Action Args
2013-03-18 12:15:30Claudiu.Popasetrecipients: + Claudiu.Popa
2013-03-18 12:15:30Claudiu.Popasetmessageid: <>
2013-03-18 12:15:30Claudiu.Popalinkissue17457 messages
2013-03-18 12:15:29Claudiu.Popacreate