【pytest】allure
【安装】
1.因为allure2需要在java的环境下,并且要求必须是jdk1.8级以上,所以要首先保证这一点
2.安装pytest:pip install pytest
3.安装allure-pytest:pip install allure-pytest
4.安装allure:
下载allure2:https://github.com/allure-framework/allure2/releases,我们下载的是allure-2.8.0版本;下载后解压,放在某个位置(建议放在C:\python35\Lib\site-packages下);配置环境变量:环境变量path中加上解压好的文件夹下的bin目录下的allure.bat文件的路径(这里是:E:\python\Lib\site-packages\allure-2.8.0\bin)
【使用】
1 #coding=GBK
2
3 import pytest
4 import allure
5 from test_api.run.run import Test_run
6 from test_api.data.get_cookies_value import get_cookies_value
7 import warnings
8 import os
9
10 @allure.feature('test-api') # feature定义功能
11 class Test_Run():
12 def setup_method(self, method): #每个模块开始之前都会执行
13 print('start.....')
14
15 @allure.story('登录/获取报文') # story定义用户场景
16 def test_1(self):
17 warnings.simplefilter("ignore", ResourceWarning)
18 # get_cookies_value()
19 a=Test_run()
20 a.run()
21 #断言
22 assert True
23
24 def teardown_method(self, method): ##每个模块结束之后都会执行
25 print('end.....')
26
27 if __name__ == '__main__':
28 # 生成配置信息 "-s 代表可以将执行成功的案例日志打印出来 ; -q+文件执行路径 代表只需要执行的文件"
29 pytest.main(['-s','-q',r'E:\python_project\request_test\pytest_allure\test_api_by_pytest.py','--alluredir','./report/xml'])
30 #os模块运行allure命令,来生成html格式的报告(根据刚刚生成的配置信息)
31 os.system("E:/python37/Lib/site-packages/allure-2.8.0/bin/allure.bat "
32 "generate "
33 "E:/python_project/request_test/pytest_allure/report/xml "
34 "-o "
35 "E:/python_project/request_test/pytest_allure/report/html")
(pytest的setup和teardown,见https://www.jianshu.com/p/a57b5967f08b)
Or:命令行执行

生成的报告如下:


作者:gtea
博客地址:https://www.cnblogs.com/gtea


浙公网安备 33010602011771号