pytest+allure实践

使用的软件版本 python 3.6.5
pycharm 2017 3.3
pytest 4.0.2
pytest-allure-adaptor 1.7.0
pytest的安装:
1.1. windows下:
pip install pytest 4.0.2
安装pytest-allure-adaptor插件
2.1. windows下:
pip install pytest-allure-adaptor
注意:一定要先操作1步骤,在操作2步骤,且pytest版本选4.0.2,如果直接运行pip install pytest,可能会发生在pycharm的terminal中运行pytest -s -q --alluredir=./allure-results命令时找不到路径,无法执行成功的情况
3.allure的安装:
3.1. windows下:
前情提示: allure是基于Java的一个程序,需要Java1.8的环境,没有安装需要去安装一下。
Windows下不能直接安装,点击此链接下载压缩包

https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.7.0/allure-2.7.0.zip

下载之后,将压缩包解压到一个磁盘中,我这里用的是D盘
pytest+allure实践_第1张图片
3.2. 配置allure的环境变量
pytest+allure实践_第2张图片
将D:\allure-2.7.0\bin路径加到系统变量中

在CMD模式下运行allure命令,如果有successful,就说明成功了

4、在已经写好的脚本文件中,在reports目录下新建一个pytest.ini文件pytest+allure实践_第3张图片
文件内容如下
[pytest]
addopots=-s -q --alluredir=./allure-results #运行python脚本,把运行的xml结果放在allure-results文件中testpaths=./test_run\tripartiteServices\rechargeinterface\rechargeoil #要运行的测试用例路径python_files=test_.py # 运行的py文件是以test开头的
python_classes=test_
# 运行的类是以test开头的
python_functions=test_* # 运行的函数是以test开头的
5、打开pycharm的terminal模式,运行 pytest命令,就可以看到测试用例的执行结果了,且在allure-results生成了xml格式的测试报告
6、运行 allure generate directory-with-results/ -o directory-with-report命令,生成allure的测试报告。
directory-with-report是指文件名称
比如我的测试报告放在项目目录下就执行 allure generate allure-results/ -o allure-report
7、运行成功后,在allure-report文件夹下找到index.html,选择谷歌运行
pytest+allure实践_第4张图片
8、测试报告
pytest+allure实践_第5张图片

Q:运行pytest的时候,可能会提示导不进去包,即ImportError: No module named XXX

A:直接在cmd命令行模式下安装 XXX包 如 pip install requests

Q:自己写的包到不进去,提示
pytest+allure实践_第6张图片
A:第1种办法:把目前已有的python删掉卸载重装
第二种办法: 在报错的脚本前加一句代码,如我的是test_rechargeinfo.py报错,
在改文件中加一句 sys.path.append(‘D:\pycharm\shall_buy_test’)
Q:在terminal中运行pytest时,提示不是可用的命令?

A:最快的解决方法是卸载现有的python,重新安装配置一次project interpreter,如下
pytest+allure实践_第7张图片

你可能感兴趣的:(工具使用)