python测试模块pytest之坑

来源:互联网 发布:jquery.checktree.js 编辑:程序博客网 时间:2024/06/05 01:08

pytest是pyhon测试代码模块,只要你安装了pytest就可以生成txt,xml,html等测试结果集,注意:生成html需要安装pytest-html模块。
pytest会寻找test或者test_开头的函数,Test开头的类去测试。我在使用pytest的时候就遇到了大坑,总结一下

很多教程都是这么教的:py.test test_class.py –html=.\report.html
他们的都能正常运行,然而我的报错了:

usage: py.test [options] [file_or_dir] [file_or_dir] [...]py.test: error: unrecognized arguments: --html=.\report.html  inifile: None  rootdir: C:\Users\LQ\Desktop\testPython

纳闷
用py.test -h查看参数,确实没找到–html这个参数,可是明明教程上的就是这么个呀,为什么呢
抱着试一试的想法,用了pytest.py -h命令试了一下,果然这里找到了–html的参数,原来使用pytest.py test_class.py –html=.\report.html这个命令,没错,执行成功了

总结:py.test能在cmd下输出详细的测试过程但不能输出html测试结果;pytest.py能输出测试结果到html以及其他的文档格式

最后:还是建议使用pytest.py命令比较好。

原创粉丝点击