1、下载allure安装包
链接:https://pan.baidu.com/s/1zI9TUun0rjqZ0jna5klg0A
提取码:0muw
2、下载完之后解压
3、然后配置环境变量,复制allure的解压目录的bin路径
4、打开控制面板–系统和安全–系统–高级系统设置–高级–环境变量–系统变量–path–编辑
5、粘贴步骤三的路径,后面加英文分号,点击确定
D:assistant toolsallureallure-2.16.0allure-2.16.0bin;
6、配置完后重启pycharm
7、打开pycharm,新建一个项目,新建一个py文件,命名为test_files.py,新建一个run.py和pytest.ini文件
8、test_files.py
class Test(): def test_name1(self): print("haha") def test_name2(self): print("xixi")
9、pytest.ini
[pytest] addopts = -vs --alluredir ./temp -p no:warnings --clean-alluredir testpaths = ./ python_files = test*.py python_classes = Test* python_funcitons = test markers = smoke:冒烟用例 usermanage:用户管理模块 productmanage:商品管理模块 filterwarnings = error ignore::UserWarning
10、run.py
import os import pytest if __name__ == '__main__': pytest.main() os.system('allure generate ./temp -o ./report --clean')
11、run.py文件,会红色波浪线标注报错,运行时提示“ModuleNotFoundError: No module named ‘pytest’”,需要安装pytest模块
需要手动安装pytest的模块,安装方式有很多种,前面的文章有写到,这里我用了最常用的方法,鼠标放在波浪线上,点击“ALT+ENTER”,点击“ENTER”,等待模块包安装成功即可
12、再次运行run文件,会报错
“ERROR: usage: run.py [options] [file_or_dir] [file_or_dir] […]
run.py: error: unrecognized arguments: --alluredir --clean-alluredir
inifile: E:pythonfilespytest.ini
rootdir: E:pythonfiles”
这里需要安装allure-pytest,这次安装我们选择命令行安装
在run.py文件里面,点击右键,选择“open in terminal”
在打开的命令行中输入“pip install allure-pytest”
安装成功
运行成功,文件夹下会新生成两个文件,分别是report和temp
选择用谷歌浏览器打开report下的index.html
即可看到漂亮的报告
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)