pytest framework_test report (allure-pytest)

First attach the code repository: https://github.com/tengfei-jiao/gisui
(1) Introduction to
allure: temptation
This translation is invincible, the super beautiful test report
Allure is a very lightweight and very flexible open source Test report generation framework, it supports most test frameworks, such as TestNG, Pytest, JUint, etc. It is simple to use and easy to integrate.

(3) The computer installs allure
pycharm and installs allure-pytest.
Why should I install it? Because after python generates the test report is a bunch of json data, you need to open the computer command line window and execute the allure command to generate the test report in html format.
how to install?

https://blog.csdn.net/weixin_43523699/article/details/101780373?ops_request_misc=&request_id=&biz_id=102&utm_term=windows%E5%AE%89%E8%A3%85allure&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-5-101780373.first_rank_v2_pc_rank_v29

(2) Commonly used methods of allure
@allure.feature('Here is level 1 feature')
@allure.story('Here is level 2 feature')
@allure.title('Here is use case title 1')
@allure.description ('Here is use case description 1')
@allure.severity('blocker') Here is the use case level, the default is normal, classification:
@allure.issue('Add defect corresponding link: https://www.baidu.com/' )
@allure.testcase('Test case link, such as: https://www.baidu.com/') For
specific content, refer to test_case_1, 2 in the code:

# coding=utf-8
import pytest
import allure
import os

@pytest.fixture()
def test_case_3():
    print('---3号用例完成---')

@pytest.fixture()
def test_case_4():
    print('---4号用例完成---')

@pytest.fixture()
def test_case_5():
    print('---5号用例完成---')

@pytest.fixture()
def test_case_6():
    print('---6号用例完成---')

@pytest.fixture()
def test_case_7():
    print('---7号用例完成---')

@pytest.fixture()
def test_case_8():
    print('---8号用例完成---')

# (1)这里按照【从下到上的顺序】,执行优先级是3、4、5
@pytest.mark.usefixtures('test_case_5')
@pytest.mark.usefixtures('test_case_4')
@pytest.mark.usefixtures('test_case_3')
class Testlogin001:

    @allure.feature('这里是1级特性')
    @allure.story('这里是2级特性')
    @allure.title('这里是用例标题1')
    @allure.description('这里是用例描述1')
    @allure.severity('blocker')
    @allure.issue('https://www.baidu.com/') #添加缺陷链接
    @allure.testcase('https://www.baidu.com/') #测试用例链接
    # 被pytest.fixture()装饰的函数,函数名可以作为变量传递给测试用例,最终在执行测试用例之前执行这个装饰过的函数
    def test_case_1(self, test_case_8):
        print('---1号用例完成---')
        with allure.step('测试步骤:'):
            allure.attach('测试步骤1')
            allure.attach('测试步骤2')


    @allure.feature('这里是1级特性')
    @allure.story('这里是2级特性')
    @allure.title('这里是用例标题2')
    @allure.description('这里是用例描述2')
    @allure.severity('critical')
    # (2)这里按照调用了前面的函数test_case_6,局部的调用,执行优先级是最高的。
    @pytest.mark.usefixtures('test_case_7')
    @pytest.mark.usefixtures('test_case_6')
    def test_case_2(self):
        print('---2号用例完成---')
        allure.attach('用例的一些test body信息')

    # 单参数单值
    @pytest.mark.parametrize('arg', [1])
    def test_case_9(self, arg):
        print("传入的值为:{}".format(arg))
        assert arg == 1

    # 单参数多值
    @pytest.mark.parametrize('arg',['abc',1,{
    
    'a':1,'b':3},(4,5)])
    def test_case_10(self, arg):
        print(f"传入的值为:{arg}")

    # 多参数多值
    @pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("5-2", 3), ("5*2", 10)])
    def test_case_11(self, test_input, expected):
        print(f"原值:{test_input} 期望值{expected}")
        assert eval(test_input) == expected

    @pytest.mark.xfail(condition=1<3, reason='该功能尚未完善,还在调测中')
    def test_case_12(self):
        print('---12号用例完成---')

    @pytest.mark.skipif(reason='test_case_13用例还在调测中')
    def test_case_13(self):
        print('---13号用例完成---')


@pytest.mark.skipif(1>3, reason='Testlogin2模块还在调测中')
class Testlogin2:

    def test_case_14(self):
        print('---14号用例完成---')


if __name__ == "__main__":

    # pytest.main(['test_1.py'])

    # 生成测试报告---json格式
    pytest.main(['--alluredir', 'D:/se_frame/Reports/allure_data', 'test_1.py'])
    # allure转换成---html并打开测试报告
    os.system('cd D:/se_frame/Reports/allure_data')
    # 清理上次的报告并生成新的报告
    os.system('allure generate D:/se_frame/Reports/allure_data -o D:/se_frame/Reports/html --clean')
    os.system('allure serve D:/se_frame/Reports/allure_data')



# 此处省略以上用例的执行结果
test_1.py::Testlogin001::test_case_12 
启动浏览器
---进入要执行模块的的界面---
---3号用例完成---
---4号用例完成---
---5号用例完成---
---12号用例完成---
XPASS (该功能尚未完善,还在调测中)
退出浏览器

test_1.py::Testlogin001::test_case_13 SKIPPED (test_case_13用例还在...)
test_1.py::Testlogin2::test_case_14 
启动浏览器
---进入要执行模块的的界面---
---14号用例完成---
PASSED
退出浏览器


--------- generated html file: file://D:\se_frame\Reports\report.html ---------
================== 11 passed, 1 skipped, 1 xpassed in 0.52s ===================
Report successfully generated to D:\se_frame\Reports\html
Generating report to temp directory...
Report successfully generated to C:\Users\ADMINI~1\AppData\Local\Temp\2657140710621107730\allure-report
Starting web server...
2021-02-21 17:47:37.966:INFO::main: Logging initialized @8977ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.1.6:62127/>. Press <Ctrl+C> to exit


Generated test report:
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45451320/article/details/113916870