• 接口自动化测试:pytest+allure基本使用


    一、环境准备:

    1、安装allure

    2、安装allure-pytest:pip install allure-pytest

    二、allure基本参数说明

     三、实践代码

    #conftest.py
    import pytest
    
    
    @pytest.fixture(scope="session")
    def login_fixture():
        """需要先登录"""
        print("前置条件")
        yield
        print("后置条件")
    #steps.py
    import allure
    
    
    @allure.step("步骤1")
    def step1():
        pass
    
    
    @allure.step("步骤2")
    def step2():
        pass
    
    
    @allure.step("步骤3")
    def step3():
        pass
    #test_demo.py
    import pytest
    import allure
    
    from test_allure.step import step1, step2, step3
    
    
    @allure.feature("用户管理模块")
    class TestDemo():
        @allure.story("测试用例标题")
        @allure.issue("http://bug.html")
        @allure.testcase("http://testcase.html")
        def test_update(self):
            """测试更新接口"""
            print("测试更新接口")
            step1()
            step2()
            step3
    
        @allure.story("测试用例标题1")
        @allure.issue("http://bug1.html")
        @allure.testcase("http://testcase1.html")
        def test_del(self):
            """测试删除接口"""
            print("测试删除接口")
            step1()
            step2()
            step3
    
    
    @allure.feature("商品管理模块")
    class TestDemo1():
        @allure.story("测试用例标题")
        @allure.issue("http://bug.html")
        @allure.testcase("http://testcase.html")
        @allure.severity("blocker")
        def test_update(self):
            """测试更新接口"""
            print("测试更新接口")
            step1()
            step2()
            step3
    
        @allure.story("测试用例标题1")
        @allure.issue("http://bug1.html")
        @allure.testcase("http://testcase1.html")
        @allure.severity("critical")
        def test_del(self):
            """测试删除接口"""
            print("测试删除接口")
            step1()
            step2()
            step3

    命令行执行pytest命令生成allure的测试报告

    pytest --alluredir ./allure/report8

    可以看到生成的是json、txt格式的数据

    在命令行执行allure命令,启动一个web服务,将上一步生成的数据生成HTML进行可视化

    allure serve ./allure/report8

    最后,可以按照allure标记过滤执行部分测试用例:

    比如:

    pytest --alluredir ./allure/report7 --allure-features 用户管理模块,商品管理模块
  • 相关阅读:
    POJ1475 Pushing Boxes 华丽丽的双重BFS
    POJ3322 Bloxorz I 无脑广搜(我死了。。。)
    CH2401 送礼物 双向搜索
    POJ2248 Addition Chains 迭代加深
    POJ3074 Sudoku 剪枝深(神?)搜
    Luogu P1120 小木棍 [数据加强版] 来来来我们一起来剪枝,剪枝,剪枝、、、
    Luogu P4095 [HEOI2013]Eden 的新背包问题 思维/动规
    Luogu P5201 [USACO19JAN]Shortcut 最短路树???
    Luogu P5122 [USACO18DEC]Fine Dining 最短路
    Luogu P1608 路径统计 最短路计数
  • 原文地址:https://www.cnblogs.com/Xiaojiangzi/p/13791365.html
Copyright © 2020-2023  润新知