![](/img/trans.png)
[英]How to test python function used to generate report using pytest?
[英]How to generate test report using pytest?
如何使用pytest生成测试报告? 我搜索了它,但我得到的都是关于覆盖率报告的。 我试过这个命令:
py.test sanity_tests.py --cov=C:\Test\pytest --cov-report=xml
但是作为参数表示它生成覆盖报告而不是测试报告。 请帮忙!!
从评论中--junitxml
:您可以使用--junitxml
参数。
$ py.test sample_tests.py --junitxml=C:\path\to\out_report.xml
您可以使用 pytest 插件“ pytest-html ”来生成 html 报告,这些报告也可以转发给不同的团队
首先安装插件:
$ pip install pytest-html
其次,只需使用以下命令运行您的测试:
$ pytest --html=report.html
您还可以在代码中使用插件提供的钩子。
import pytest
from py.xml import html
def pytest_html_report_title(report)
report.title = "My very own title!"
我还没有尝试过,但您可以尝试参考https://github.com/pytest-dev/pytest-html 。 一个可以生成 HTML 输出的 python 库。
py.test --html=Report.html
您也可以在此处指定您的 python 文件。 在这种情况下,当没有指定文件时,它会选择运行命令的目录中存在的所有名称类似于“test_%”的文件并执行它们并生成名为 Report.html 的报告
您还可以相应地修改报告的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.