以下超級簡單單元測試在python2.7下運行正常,但在2.6中給出了以下錯誤 「no method runTest()」,爲什麼?python單元測試怪異問題
謝謝! 陽
[email protected] /tmp $ python26 -m unittest a.AA
Traceback (most recent call last):
File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/usr/lib64/python2.6/unittest.py", line 874, in <module>
main(module=None)
File "/usr/lib64/python2.6/unittest.py", line 815, in __init__
self.parseArgs(argv)
File "/usr/lib64/python2.6/unittest.py", line 842, in parseArgs
self.createTests()
File "/usr/lib64/python2.6/unittest.py", line 848, in createTests
self.module)
File "/usr/lib64/python2.6/unittest.py", line 612, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib64/python2.6/unittest.py", line 597, in loadTestsFromName
test = obj()
File "/usr/lib64/python2.6/unittest.py", line 215, in __init__
(self.__class__, methodName)
ValueError: no such test method in <class 'a.AA'>: runTest
[email protected] /tmp $ vi a.py
[email protected] /tmp $ cat a.py
import unittest
class AA(unittest.TestCase):
pass
謝謝,但是文檔http://docs.python.org/release/2.6.6/library/unittest.html#basic-example中的第一個簡單示例沒有runTest()覆蓋? –
由於它實現了名爲test_something的函數,因此單元測試可以理解爲測試函數。 – tomahh
我添加了一個test_blah()測試,還是一樣 進口單元測試 AA級(unittest.TestCase生成): 高清test_blah(個體經營): 的assertEquals(1,1, 'SIMPL') –