[issue7872] Incorrect error raised on importing invalid module via unittest

Daniel Waterworth report at bugs.python.org
Sun Feb 7 14:19:29 CET 2010


New submission from Daniel Waterworth <da.waterworth at googlemail.com>:

The problem is that when you import a module which is inside a package via 'loadTestsFromName' in unittest.TestLoader. If the imported module raises a ImportError this is read to mean that the module itself is unavailable.

To illustrate this I have a small test-case. First run the file runtests.py in python or python3. Next uncomment the first line in test/test.py and run again. The error I receive is:

Traceback (most recent call last):
  File "runtests.py", line 3, in <module>
    suite = unittest.TestLoader().loadTestsFromName("test.test")
  File "/usr/lib/python2.6/unittest.py", line 584, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test'

Whereas I believe this should raise an "ImportError: No module named none_existant_module", just like it does when you try to import the module directly.

This would make the error more descriptive and therefore bugs of this nature easier to track down.

----------
components: Library (Lib)
files: testcase.tar.bz2
messages: 98997
nosy: Daniel.Waterworth
severity: normal
status: open
title: Incorrect error raised on importing invalid module via unittest
type: behavior
versions: Python 3.1
Added file: http://bugs.python.org/file16166/testcase.tar.bz2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7872>
_______________________________________


More information about the Python-bugs-list mailing list