什么正是我需要做的,使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()
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,测试只是没有运行,我不知道为什么(因为我不是python程序员).仅供参考,我使用的__init__.py是python …