Using Python 2.6, I have a very simple test in a python file in a directory:
#mytest.py
import unittest
class BasicTests(unittest.TestCase):
def test_ok(self):
self.assertTrue(True)
suite = unittest.TestLoader().loadTestsFromTestCase(BasicTests)
I change into the directory and run python -m unittest mytest.suite
and I get the following error:
Traceback (most recent call last):
File "/usr/lib/python2.6/runpy.py", line 122, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/usr/lib/python2.6/unittest.py", line 875, in <module>
main(module=None)
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 598, in loadTestsFromName
test = obj()
File "/usr/lib/python2.6/unittest.py", line 464, in __call__
return self.run(*args, **kwds)
TypeError: run() takes exactly 2 arguments (1 given)
I've tried several variations (such as unittest.makeSuite
and unittest.LoadTestFromNames
) but they all give me the same basic error. What am I missing? I keep reading the documentation and I seem to be following the spec.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…