• Pytest学习笔记5——Allure测试报告用例详细描述


      引言

      如果做完自动化测试后,生成的结果可读性不强,那将会是一次失败的自动化测试。

      pytest自动化测试中,要想报告内容丰富,优雅和可读性强,就需要与allure结合使用。

      allure报告有很多特性,这些特性主要以装饰器、函数等的方式使用。

      Allure装饰器描述    

      案例解析

      在testcase新建conftest.py文件:

    import pytest
    
    @pytest.fixture()
    def action():
        print("测试开始".center(30,'*'))
        yield
        print("测试结束".center(30,'*'))

      在测试文件testcase下新建测试文件test_qq.py文件:

    import allure
    from common import Log
    import requests
    
    @allure.step('这是测试步骤')
    def step_1():
        print("初始化数据")
    
    
    
    @allure.epic('测试天气API接口'.center(30,'*'))
    @allure.feature('测试模块')
    @allure.suite('这是套件')
    class TestHttpbin:
        """测试模块httpbin"""
        def setup(self):
            """所有用例执行前的条件"""
            self.logger = Log.MyLog()
    
    
        @allure.severity('normal')
        @allure.story('故事1:获取天气数据')
        @allure.title('获取单个城市的天气')
        @allure.description('获取深圳的天气')
        @allure.testcase('测试用例地址:www.***.com')
        @allure.issue('缺陷管理地址:https://www.zentao.net/')
        @allure.tag('这是tag')
        def test_001(self,action):
            """
            测试httpbin接口:get方法
            """
            step_1()
            # api:host
            url = 'https://tianqiapi.com/api'
            params = {'version':'v6','appid':12253812,'appsecret':'KzT8yOpX'}
    
            response = requests.get(url=url,params=params).json()
            print('接口返回数据: %s'%response)
            self.logger.info('接口返回数据: %s' % response)
    

      

      报告生成

    # 方法1
    # 切换到testcase目录下
    pytest -v test_qq.py --alluredir allure_report
    allure serve allure_report
    

      

      运行结果:

      命令行参数

    pytest运行用例的时候可以加上allure标记用例的参数

    --allure-severities=SEVERITIES_SET
                            Comma-separated list of severity names. Tests only
                            with these severities will be run. Possible values
                            are: blocker, critical, normal, minor, trivial.
    --allure-epics=EPICS_SET
                            Comma-separated list of epic names. Run tests that
                            have at least one of the specified feature labels.
    --allure-features=FEATURES_SET
                            Comma-separated list of feature names. Run tests that
                            have at least one of the specified feature labels.
    --allure-stories=STORIES_SET
                            Comma-separated list of story names. Run tests that
                            have at least one of the specified story labels.
    --allure-link-pattern=LINK_TYPE:LINK_PATTERN
                            Url pattern for link type. Allows short links in test,
                            like 'issue-1'. Text will be formatted to full url
                            with python str.format().
    

      

    # 选择运行你要执行epic的用例
    pytest --alluredir ./report/allure --allure-epics=epic对大Story的一个描述性标签
    # 选择运行你要执行features的用例
    pytest --alluredir ./report/allure --allure-features=模块2
    # 选择运行你要执行features的用例
    pytest --alluredir ./report/allure --allure-stories="用户故事:1"
    

      

      总结

      以上就是pytest+allure关于测试用例描述的基本使用方法。

      如果对你有帮助或喜欢自动化测试开发的朋友,可以加入右下方QQ交流群学习与探索,更多干货与你分享。

  • 相关阅读:
    将来要干啥
    选新技术考虑点
    hdfs 创建一个新用户
    linux下实现mysql数据库定时备份
    PostgreSQL的安装和卸载,远程连接
    PostgreSQL语法
    【NiFi系列】1-基本介绍
    大数据相关资源网址
    MySQL主从复制配置
    MySQL设置免密登录
  • 原文地址:https://www.cnblogs.com/liudinglong/p/13056109.html
Copyright © 2020-2023  润新知