(1)pytest-html
插件
Pytest可以通过命令⾏⽅式,⽣成xml/html
格式的测试报告,并存储于⽤户指定路径。
需要用到pytest-html
插件。
安装⽅式:pip install pytest-html
插件使用方式:
命令格式:--html=⽤户路径/report.html
运⾏⽅式:
-
main()函数方式:
pytest.main(['--html=./report/report_01.html'])
(不好使,可能配置了pytest.ini
文件) -
命令行方式:
在report目录中生成
report.html
测试报告。pytest ./pytest_demo/test_pytest_01.py --html=./report/report.html
-
使用
pytest.ini
文件方式:在
addopts
属性后追加--html
参数配置,在report目录中生成report.html
测试报告。addopts = -s --html=../report/report.html
执⾏结果:
在指定⽬录中会⽣成assets
⽂件夹(css文件)和report.html
⽂件,如下图: