pytest进阶 -- 结合Html / Allure生成测试报告
warning:
这篇文章距离上次修改已过456天,其中的内容可能已经有所变动。
要在Pytest中结合HTML和Allure生成测试报告,你需要安装pytest-html和allure-pytest这两个插件。
- 安装插件:
pip install pytest pytest-html allure-pytest- 在
pytest.ini配置文件中启用插件(如果没有则创建):
[pytest]
addopts = -v --html=report.html --alluredir=allure-results
markers =
smoke: marks test as smoke tests
regression: marks test as regression tests- 使用命令行运行测试,生成报告:
pytest --alluredir=allure-results
allure generate allure-results -o allure-report --clean这里,--html=report.html 会生成一个HTML格式的测试报告,--alluredir=allure-results 会将Allure测试报告数据保存在allure-results目录。allure generate 命令用于生成最终的Allure报告,并输出到allure-report目录。
- 示例代码:
# test_example.py
import pytest
@pytest.mark.smoke
def test_example1():
assert 1 == 1
@pytest.mark.regression
def test_example2():
assert 2 == 2运行测试后,你将得到一个HTML报告和一个Allure报告。
评论已关闭