[New-bugs-announce] [issue7559] TestLoader.loadTestsFromName swallows import errors

Robert Collins report at bugs.python.org
Mon Dec 21 22:07:17 CET 2009


New submission from Robert Collins <robertc at robertcollins.net>:

Say I have a test module test_foo, which fails to import with
ImportError. A reason for this might be a misspelt import in that module.

TestLoader().loadTestsFromName swallows the import error and instead
crashes with:
  File "/usr/lib/python2.6/unittest.py", line 584, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_foo'

A better thing to do would be to keep the import error and if the next
probe is an Attribute error, reraise the import error.
An alternative would be to return a test which would then reraise the
import error permitting the test suite to be constructed and execute but
still reporting the error.

----------
components: Library (Lib)
messages: 96770
nosy: rbcollins
severity: normal
status: open
title: TestLoader.loadTestsFromName swallows import errors

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


More information about the New-bugs-announce mailing list