[issue13932] If some test module fails to import another module unittest reports a very misleading message

Sébastien Barthélémy report at bugs.python.org
Fri Feb 3 16:50:44 CET 2012


New submission from Sébastien Barthélémy <barthelemy at crans.org>:

If some test module (say, testmath) fails to import some other module, unittest reports a very misleading message:

  AttributeError: 'module' object has no attribute 'testmath'

Would it be possible improve the message or, better, to simply make the test as failed. (Maybe be by inspecting the ImportError exception message).

Consider the following example (and notice the typo at "import mathhh"):

mkdir -p test
touch test/__init__.py
cat > test/testmath.py <<EOL
import unittest
import mathhh
class MathTestCase(unittest.TestCase):
    def testSin(self):
        self.assertEqual(math.sin(0), 0)
EOL
python -m unittest test.testmath

it returns 

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/unittest/__main__.py", line 12, in <module>
    main(module=None)
  File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python2.7/unittest/main.py", line 149, in parseArgs
    self.createTests()
  File "/usr/lib/python2.7/unittest/main.py", line 158, in createTests
    self.module)
  File "/usr/lib/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'testmath'

----------
components: Library (Lib)
messages: 152525
nosy: sbarthelemy
priority: normal
severity: normal
status: open
title: If some test module fails to import another module unittest reports a very misleading message
versions: Python 2.7

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


More information about the Python-bugs-list mailing list