【发布时间】:2011-12-05 09:58:20
【问题描述】:
究竟我需要做什么才能使 python 的 unittest 工作?我检查了官方文档,SO问题,甚至尝试使用nose,但到目前为止没有任何效果。我做错了什么?
bash:~/path/to/project/src/tests$ ls -l
total 8
-rw-r--r-- 1 myuser myuser 342 Out 11 11:51 echo_test.py
-rw-r--r-- 1 myuser myuser 71 Out 11 11:28 __init__.py
bash:~/path/to/project/src/tests$ python -m unittest -v echo_test
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
bash:~/path/to/project/src/tests$ python -m unittest discover
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
bash:~/path/to/project/src/tests$ cat echo_test.py
import unittest
class EchoTest(unittest.TestCase):
def fooTest(self):
self.assertTrue(1==1)
def barTest(self):
self.assertTrue(1==2)
#suite = unittest.TestLoader().loadTestsFromTestCase(TestEcho)
#unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
unittest.main()
如您所见,测试根本没有运行,我不知道为什么(因为我不是 python 程序员)。
仅供参考,我使用的是 python 2.7,__init__.py 是一个空文件。
有什么想法吗?
【问题讨论】:
标签: python unit-testing python-2.7