Ita*_*iss 4 python continuous-integration unit-testing nose
如何从脚本中的python文件运行所有测试(unittest.TestCase)?
我尝试使用鼻子,但似乎总是运行测试发现.我想要的只是导入一个模块,给一些函数一个路径并获得测试结果,任何建议?
在测试脚本的底部放
if __name__ == '__main__':
unittest.main()
Run Code Online (Sandbox Code Playgroud)
然后正常调用您的文件
$ python my_test_script.py
Run Code Online (Sandbox Code Playgroud)
(可选)如果要使用nose或者pytest,只需为其指定要运行的脚本的名称,它仍将执行发现,但仅限于该文件.
$ nosetests my_test_script.py
$ py.test my_test_script.py
Run Code Online (Sandbox Code Playgroud)
如果你是从python内部运行鼻子,你可以使用 nose.run()
my_script.py
import nose
nose.run()
Run Code Online (Sandbox Code Playgroud)
默认情况下,它将使用您传递给脚本的参数,因此如果您只想运行单个test_script
$ python my_script.py /path/to/test_script.py
Run Code Online (Sandbox Code Playgroud)
或者,您可以直接在脚本中传递参数
nose.run(argv=[__file__, '/path/to/test_script'])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1213 次 |
| 最近记录: |