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.

classification
Title: Incorrect error raised on importing invalid module via unittest
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: Daniel.Waterworth, ezio.melotti, michael.foord
Priority: normal Keywords:

Created on 2010-02-07 13:19 by Daniel.Waterworth, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testcase.tar.bz2 Daniel.Waterworth, 2010-02-07 13:19
Messages (2)
msg98997 - (view) Author: Daniel Waterworth (Daniel.Waterworth) Date: 2010-02-07 13:19
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.
msg99001 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-02-07 14:15
Duplicate of issue 7559.
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52120
2010-02-07 14:15:08michael.foordsetstatus: open -> closed
resolution: duplicate
messages: + msg99001

stage: test needed -> resolved
2010-02-07 13:21:48ezio.melottisetpriority: normal
nosy: + ezio.melotti, michael.foord
versions: + Python 2.6, Python 2.7, Python 3.2

stage: test needed
2010-02-07 13:19:27Daniel.Waterworthcreate