homepage

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 sbarthelemy
Recipients sbarthelemy
Date 2012年02月03日.15:50:43
SpamBayes Score 2.5144276e-11
Marked as misclassified No
Message-id <1328284244.56.0.791299564661.issue13932@psf.upfronthosting.co.za>
In-reply-to
Content
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'
History
Date User Action Args
2012年02月03日 15:50:44sbarthelemysetrecipients: + sbarthelemy
2012年02月03日 15:50:44sbarthelemysetmessageid: <1328284244.56.0.791299564661.issue13932@psf.upfronthosting.co.za>
2012年02月03日 15:50:43sbarthelemylinkissue13932 messages
2012年02月03日 15:50:43sbarthelemycreate

AltStyle によって変換されたページ (->オリジナル) /