[pyunit] Only run one specific test
Nikolaus Rath
Nikolaus at rath.org
Wed May 27 19:08:25 EDT 2009
Hi,
Consider these two files:
,---- mytest.py -----
| #!/usr/bin/env python
| import unittest
|
| class myTestCase(unittest.TestCase):
| def test_foo(self):
| pass
|
| # Somehow important according to pyunit documentation
| def suite():
| return unittest.makeSuite(myTestCase)
`----
,---- runtest ---
| #!/usr/bin/env python
| import unittest
|
| # Find and import tests
| modules_to_test = [ "mytest" ]
| map(__import__, modules_to_test)
|
| # Runs all tests in test/ directory
| def suite():
| alltests = unittest.TestSuite()
| for name in modules_to_test:
| alltests.addTest(unittest.findTestCases(sys.modules[name]))
| return alltests
|
| if __name__ == '__main__':
| unittest.main(defaultTest='suite')
`----
if I run runtest without arguments, it works. But according to runtest
--help, I should also be able to do
,----
| $ ./runtest mytest
| Traceback (most recent call last):
| File "./runtest", line 20, in <module>
| unittest.main()
| File "/usr/lib/python2.6/unittest.py", line 816, in __init__
| self.parseArgs(argv)
| File "/usr/lib/python2.6/unittest.py", line 843, in parseArgs
| self.createTests()
| File "/usr/lib/python2.6/unittest.py", line 849, in createTests
| self.module)
| File "/usr/lib/python2.6/unittest.py", line 613, in loadTestsFromNames
| suites = [self.loadTestsFromName(name, module) for name in names]
| File "/usr/lib/python2.6/unittest.py", line 584, in loadTestsFromName
| parent, obj = obj, getattr(obj, part)
| AttributeError: 'module' object has no attribute 'mytest'
`----
Why doesn't this work?
Best,
-Nikolaus
--
»Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
More information about the Python-list
mailing list