飞道的博客

pytest allure的简单介绍

455人阅读  评论(0)

allure一款测试报告框架,具有以下几个特点

  • allure是一个轻量级,灵活的,支持多语言的测试报告工具;
  • java语言开发的,支持pytest,PHP等;
  • 可以提供详细的测试报告,测试步骤,log;
  • 可以集成到Jenkins

1.安装
使用pip命令安装

pip install allure-pytest

使用pip list查看是否有该组件
我们使用的windows环境安装,同时我们下载一个allure-2.7.0.zip的文件,将其bin目录配置到环境变量Path中,例如:

在cmd中输入allure,出现以下界面,即配置成功:

C:\Users\shaem>allure
Usage: allure [options] [command] [command options]
  Options:
    --help
      Print commandline help.
    -q, --quiet
      Switch on the quiet mode.
      Default: false
    -v, --verbose
      Switch on the verbose mode.
      Default: false
    --version
      Print commandline version.
      Default: false
  Commands:
    generate      Generate the report
      Usage: generate [options] The directories with allure results
        Options:
          -c, --clean
            Clean Allure report directory before generating a new one.
            Default: false
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.
          -o, --report-dir, --output
            The directory to generate Allure report into.
            Default: allure-report

    serve      Serve the report
      Usage: serve [options] The directories with allure results
        Options:
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0
          --profile
            Allure commandline configuration profile.

    open      Open generated report
      Usage: open [options] The report directory
        Options:
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0

    plugin      Generate the report
      Usage: plugin [options]
        Options:
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.

2.allure用例描述

代码如下:

import allure
import pytest


@pytest.fixture(scope="session")
def login():
    print("用例先登录")


@allure.step("步骤1:点xxx")
def step_1():
    print("111")


@allure.step("步骤2:点xxx")
def step_2():
    print("222")


@allure.feature("编辑页面")
class TestEditPage():
    '''编辑页面'''

    @allure.story("这是一个xxx的用例")
    def test_1(self, login):
        '''用例描述:先登录,再去执行xxx'''
        step_1()
        step_2()
        print("xxx")

    @allure.story("打开a页面")
    def test_2(self, login):
        '''用例描述:先登录,再去执行yyy'''
        print("yyy")

第一步:在pycharm的命令行输入:pytest --alluredir reports testcases/pytest/test_allure.py
reports为保存报告相关数据的信息
第二步:执行allure serve reports,浏览器默认会弹出一个html页面


转载:https://blog.csdn.net/dingding_ting/article/details/117172718
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场