pytest学习和使用-HTML报告如何生成?(pytest-html)_from py
    		       		warning:
    		            这篇文章距离上次修改已过442天,其中的内容可能已经有所变动。
    		        
        		                
                在Pytest中,你可以使用pytest-html插件来生成HTML格式的测试报告。以下是如何使用该插件的步骤:
- 安装
pytest-html插件: 
pip install pytest-html- 使用命令行参数
--html或者配置文件中的pytest_html选项来生成报告: 
命令行方式:
pytest --html=report.html配置文件方式(pytest.ini):
[pytest]
addopts = --html=report.html- 运行你的测试用例,之后在当前目录下会生成一个
report.html的报告文件。 
如果你想要自定义报告的标题、样式等,可以在调用pytest时指定--html参数后面的路径为一个Python字典,例如:
pytest --html=report.html --self-contained-html这将生成一个自包含的HTML报告,包含所有必须的资源。如果你想要更详细的配置,可以在Python脚本中使用pytest.main()函数,并传递配置字典:
import pytest
 
pytest.main([
    '--html=report.html',
    '--html-report-stylesheet=my_style.css',
    'tests/'
])在这个例子中,my_style.css是你提前准备的CSS样式表,它将覆盖默认的样式来定制你的HTML报告。
评论已关闭