宁波网站排名方法,中国互联网数据平台官网,扬中网络推广,新建文档怎么做网站一、完整步骤
常规allure报告的生成方法是在pytest全部用例执行完成后#xff0c;手动在命令行执行如 allure generate ./temps -o ./report --clean每次用例执行完成后都要重复如此的操作#xff0c;十分繁琐。
可以使用如下方式让用例执行完成后自动生成报告到当前目录下…一、完整步骤
常规allure报告的生成方法是在pytest全部用例执行完成后手动在命令行执行如 allure generate ./temps -o ./report --clean每次用例执行完成后都要重复如此的操作十分繁琐。
可以使用如下方式让用例执行完成后自动生成报告到当前目录下
1、首先在pytest.ini里面配置。如没有则在根目录下创建
[pytest]
addopts -vs --alluredir./temps --clean-alluredir
2、其次在conftest.py里面新增如下代码。如没有则在根目录下创建
import osdef pytest_sessionfinish(session, exitstatus):os.system(allure generate ./temps -o ./report --clean)则可以在用例执行完成后自动生成报告。
二、代码讲解
1、ini配置文件
[pytest]
addopts -vs --alluredir./temps --clean-alluredir -v 作用: 增加详细输出。 说明: 使 pytest 输出更详细的测试结果包括每个测试用例的状态和输出信息。 -s 作用: 允许打印到控制台。 说明: 禁止 pytest 捕获标准输出和标准错误输出允许测试脚本中的 print 语句正常输出到控制台。 --alluredir./temps 作用: 指定生成 Allure 测试结果文件的目录。 说明: 将测试结果保存到指定目录这里是 ./temps以便后续生成 Allure 报告。 --clean-alluredir 作用: 清空指定的 Allure 结果目录。 说明: 在生成新的测试结果之前清空指定的目录这里是 ./temps避免旧的结果文件干扰新结果。 2、conftest.py
import osdef pytest_sessionfinish(session, exitstatus):os.system(allure generate ./temps -o ./report --clean)定义一个 pytest 的 hook 函数 pytest_sessionfinish 执行 Allure 报告生成命令os.system(allure generate ./temps -o ./report --clean) 三、踩坑
之前直接在fixture中编写os代码期望能够在用例执行完成后生成报告但受到pytest框架的影响会导致用例缺失我有十个用例在fixture里面执行完后只有9个用例的报告
pytest.fixture(scopesession, autouseTrue)
def generate_allure_report(request):yieldos.system(allure generate ./temps -o ./report --clean)