allure插件安装

为了解决安装allure后执行命令后报错module 'pytest' has no attribute 'allure'的问题,发现之前安装了pytest-allure-adaptor

如果存在安装过的pytest-allure-adaptor插件,先卸载:pip uninstall pytest-allure-adaptor

重新安装allure-pytest:pip install allure-pytest

Allure帮助文档: https://docs.qameta.io/allure/#_about

生成Allure报告: 命令行参数:pytest --alluredir report  # 在执行命令目录生成report文件夹,文件夹下包含xml文件

在包里新建配置文件pytest.ini:

 1 [pytest]
 2 ;--html=./report.html
 3 ;删除原生html,增加Allure
 4 addopts = -s --alluredir report
 5 # 测试路径
 6 testpaths = ./Test
 7 # 测试文件名
 8 python_files = test_*.py
 9 # 测试类名
10 python_classes = Test_*
11 # 测试的方法名
12 python_functions = test_*

新建test_001.py:

 1 import pytest
 2 
 3 
 4 class Test_Abc:
 5 
 6     def test_abc_001(self):
 7         assert 1
 8 
 9 
10 if __name__ == '__main__':
11     pytest.main("-s --alluredir report test_001.py")
 

操作步骤:

1.命令行进入pytest.ini所在目录

2.输入命令:pytest

执行结果:

pytest.ini所在目录生成report文件夹,文件夹下生成一个xml文件

猜你喜欢

转载自www.cnblogs.com/liangjt/p/12907305.html
今日推荐