如何利用Pytest 框架输出JSON格式的测试报告
- 安装第三方插件:
通过PIP在命令行终端安装pytest-json, 输入 : >pip install pytest-json - 运行需要执行的PY文件:> py.test --json=report.json
- 如下示例:
>pytest -s -m needsrun --json=test_report.json --file ./test_case1.json
最后会在你指定的目录生成一个JSON文件,即就是测试报告
*** 更新*************************************
如果上面的方法不可用,可更新pip到最新版本,命令行安装
pip install pytest-json-report
然后执行:
pytest --json-report --json-report-indent=2 --json-report-file=fanxxx.json
或
pytest --json-report -v tests/
或
pytest -s -m needsrun --json-report --json-report-indent=2 --json-report-file=fanxxx.json --file ./test_config/test_seq_xxx.json
参考官网链接:https://pypi.org/project/pytest-json-report/