python生成测试报告_pytest+Allure生成测试报告

首先安装pytest

pip install pytest1

安装pytest的allure插件

pip install pytest-allure-adaptor1

安装allure,因为allure依赖于java环境,所以必须先安装java环境并设置环境变量(自行百度就可以)。

去以下链接,下载一个包,解压后将bin路径设置到环境变量path中

https://github.com/allure-framework/allure2/releases

path环境变量如下图所示,

这样就可以通过cmd中的allure命令来生成测试报告

我在测试过程中提示module ‘pytest’ has no attribute ‘allure’,以下这篇文章可以解决:

https://www.cnblogs.com/lansan0701/p/10345142.html

装好以后,来写个demo

#coding=utf-8

import pytest

import allure

marketid = ['101','102']

testlist = ['1','test','test1']

testlist2 = ['test0','test2','test3']

#市场id对应也生成相同的数组

@pytest.fixture(scope='module',autouse=True)

@allure.feature('测试准备')

def prepare():

print('这是测试准备哦')

yield

print('module 测试结束')

@allure.feature('期权强平测试')

class Test_module1:

@allure.feature('期权市价委托强平')

@pytest.mark.parametrize('str1',testlist)

@pytest.mark.parametrize('str2',testlist2)

def test1(self,str1,str2):

"""

用例描述:期权强平市价委托

"""

stradd = str1 + str2

print('这是test1')

assert 1 == 2

@allure.feature('期权限价委托强平')

def test2(self):

with allure.step("调节持仓"):

x = '1'

allure.attach(x)

print('这是test2')

with allure.step('进行强平的操作'):

print('DTE')

class Test_module2:`在这里插入代码片`

def test3(self):

with allure.step("调节持仓"):

x = '1'

allure.attach(x)

print('这是test2')

with allure.step('进行强平的操作'):

print('DTE')1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

我用的是pycharm,在pycharm的Terminal中输入命令:

pytest -s -q --alluredir report1

这时候生成的是一堆json文件,不方便查看,大概长这样:

需要用刚才安装的allure command-line工具生成html格式的测试报告,在cmd中输入:

allure generate --clean report1

来看一下生成的报告路径:

打开上面图那个html,看一眼呗:(如果要用chrome打开,则必须在pycharm右键使用chrome打开,如果直接打开文件的话会404,不清楚原因,不过直接用firefox浏览器打开文件可以正常显示)

allure的其他用法,可以去官网看它的document和examples:

http://allure.qatools.ru/

行吧,测试报告就先整成这样吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值