一、Pytest-html插件生成测试报告
1.在pytest.ini配置文件
#即在当前目录下生成report.html测试报告文件
[pytest]
addopts= --html ./report.html
testpaths=./test_01.py
..........
..........
测试报告示例:
二、allure-pytest插件生成allure测试报告
1、下载,解压,配置path路径
地址:https://github.com/allure-framework/allure2/releases
2、在pytest.ini文件中加入命令,生成json格式的临时报告
命令:--alluredir=./temp (#在当前目录下的temp文件夹存放json文件)
3、生成allure测试报告
#在report目录下存放测试报告
os.system('allure generate ./temp -o ./report')
或
#执行测试用例
if __name__ == '__main__':
#先将测试生成数据存放在当前路径下的allure-results文件中
pytest.main(['-vs','test_login.py','--alluredir','./allure-results'])
#在reports目录下存放测试报告
os.system('allure generate ./allure-results -o ./reports ')
注释:
allure generate
:固定格式命令
./temp
:临时的json格式报告的路径
-o
: 输出参数(output)
./report
:生成的allure报告的路径
--clean
: 清空./report路径原来的报告
报告示例: