确保已在项目中正确安装了Allure Test Report工具。
在测试用例中使用Allure注释进行测试报告的指定。示例代码如下:
import allure
@allure.feature('测试报告') def test_report(): with allure.step('测试步骤1'): assert True with allure.step('测试步骤2'): assert False
$ pytest --alluredir=./allure-results
$ allure generate ./allure-results --clean -o ./allure-report $ allure open ./allure-report
$ pip install allure-pytest $ pip install allure-plotly
import allure import pytest
@pytest.fixture def allure_title(request): return ' | '.join(request.module.name.split('.')[1:])
def test_func(allure_title): with allure.step('这是一个绘图步骤'): plot = [ { 'x': [1, 2, 3, 4, 5], 'y': [1, 2, 4, 8, 16], 'type': 'scatter', 'name': 'y = 2^x' } ] layout = { 'title': allure_title, 'xaxis': {'title': 'x'}, 'yaxis': {'title': '2^x'} } allure.attach(plot, name='Chart', attachment_type=allure.attachment_type.PNG) allure.attach(str(layout), name='Layout', attachment_type=allure.attachment_type.TEXT) with allure.step('这是一个共享的图表'): allure.plot(plot, layout)
python -m pytest --alluredir=./allure-results
生成报告并