美文网首页测试那些事儿
Pytest+Allure环境的搭建

Pytest+Allure环境的搭建

作者: 少杰创业笔记 | 来源:发表于2018-11-13 16:22 被阅读1384次

1. pytest的安装:

1.1. windows下:

pip install pytest

1.2. linux下:

pip install pytest

2. 安装pytest-allure-adaptor插件

2.1. windows下:

pip install pytest-allure-adaptor

3. allure的安装:

3.1. windows下:

前情提示: allure是基于Java的一个程序,需要Java1.8的环境,没有安装需要去安装一下。

Windows下不能直接安装,点击此链接下载压缩包

下载之后,将压缩包解压到一个磁盘中,我这里用的是F

image

3.2. 配置allure的环境变量

image image

点击确定,保存。这样就可以通过CMD使用allure命令

3.3. 编写测试文件

pycharm新建一个test_demo.py文件,代码如下:

import allure


@allure.MASTER_HELPER.feature("测试Dome")
class TestDome(object):

    @allure.MASTER_HELPER.step("定义被测函数")
    def func(self, x):
        return x+1

    @allure.MASTER_HELPER.story("被测场景")
    @allure.MASTER_HELPER.severity("blocker")
    @allure.MASTER_HELPER.step("断言结果")
    def test_func(self):
        # with allure.MASTER_HELPER.step("断言结果"):
        allure.MASTER_HELPER.attach("预期结果", "{}".format(self.func(3)))
        allure.MASTER_HELPER.attach("实际结果", "{}".format(5))
        assert self.func(3) == 5

3.4. 生成测试报告

pycharm中打开terminal

image

输入命令pytest -s --alluredir=report,会遇到以下这个错误:

image

进入allure下面的utils文件,修改以下代码:

# utils文件,可以通过from allure import utlis进入

for suitable_name in suitable_names:
            # markers.append(item.get_marker(suitable_name))
            markers.append(item.get_closest_marker(suitable_name))

image

修改之后,再次运行pytest -s --alluredir=report命令:

image

运行后,无上述错误,同时会生成一个report文件。其中会有一个xml格式的报告:

image image

当然xml格式的报告不够直观,我们需要通过allure将它转成HTML格式的报告。通过cmd命令cdreport的根目录下,执行allure generate --clean report

image

回到根目录下,会生成一个allure-report的文件夹,在pycharm中打开文件夹,点击index.html运行

image

ok,到此为止。可以看到我们的精美的测试报告了

image image

相关文章

  • Pytest+Allure环境的搭建

    1. pytest的安装: 1.1. windows下: 1.2. linux下: 2. 安装pytest-all...

  • 学习笔记-Pytest+Allure环境搭建

    1. allure简介 Allure是一款非常轻量级并且非常灵活的开源测试报告生成框架。 它支持绝大多数测试框架,...

  • pytest+allure搭建

    PS:最近在公司工作量不是很大,所以有点时间研究一下各个框架,看看之间的优缺点和特性,方便后面工作测试方案的选择。...

  • 接口自动化pytest+allure环境搭建

    1.背景:之前的接口自动化框架是unittest+HTMLTestRunner,最近看了好多测试的文章都在发pyt...

  • pytest集成allure

    pytest+allure生成报告 安装allure插件 先解压到software目录下 环境变量中配置下allu...

  • pytest+allure 搭建环境+执行生成测试报告

    allure是用来生成测试报告的。是一个灵活的开源的轻量级的多平台支持的测试报告框架。 https://githu...

  • React Native学习总结篇

    一、环境搭建 1.1 React Native环境搭建 1.1.1 IOS环境搭建 环境:MacOS 注意:不要使...

  • Gradle开发-Groovy环境搭建

    ##Groovy环境搭建 在使用 Groovy 之前首先要搭建几个环境: Groovy 的环境搭建 JDK 环境搭...

  • linux 第四天

    Lamp环境搭建 /*******************Lamp环境搭建:*******************...

  • codePush说明

    codePush环境搭建 环境搭建文章:环境搭建 git地址:codePush git地址2.0.3,And...

网友评论

    本文标题:Pytest+Allure环境的搭建

    本文链接:https://www.haomeiwen.com/subject/irslfqtx.html