mac使用allure_pytest+allure在mac下配置和报告输出

一.其他环境预装

1.java 1.8

二.allure安装(下载包安装)

三.allure环境配置

vim .bash_profile打开配置文件,追加配置

使用i,在文件下追加文件存放位置

4dd23b7e1565

image.png

追加内容如下:

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

export PATH=${PATH}:/env/allure-2.7.0/bin

备注:

1.第二句为你本地allure解压的文件夹,注意要进入到bin目录下

2.第一句如果不配置,在运行自动化用例生成allure报告的时候会报错sh:allure command not find,解决方案就是追加第一句配置,重启pycharm

esc键退出文本编辑模式,:wq保存退出

source .bash_profile刷新文件生效

4.安装版本检查,展示结果如下

allure --version

4dd23b7e1565

image.png

四.运行测试用例输出报告

在pycharm安装pytest和allure-pytest

pip install pytest

pip install allure-pytest

2.给测试用例标记allure注解

import pytest

import logging

import allure

logging.basicConfig(level=logging.DEBUG)

log = logging.getLogger('testmodel')

def setup_module():

log.debug('xianzhixing')

print('xianzhixing')

def teardown_module():

log.debug('houzhixing')

print('houzhixing')

@allure.feature("模型测试模块")

class TestModel:

def setup_method(self):

print('setupmethod')

def teardown_method(self):

print('teardownmethod')

@allure.story("测试test_tt")

def test_tt(self):

print('ssssss')

@allure.story("测试test_mm")

def test_mm(self):

print('test mm')

@allure.story("测试test_ff")

def test_ff(self):

print('test ff')

3.在项目根目录下创建报告结果文件夹和生成报告文件夹

4dd23b7e1565

image.png

4.allure-result文件夹下创建环境配置文件environment.properties,配置如下

Browser=Chrome

Browser.Version=63.0

Stand=Production

ApiUrl=127.0.0.1/login

python.Version=3.9

5.创建run.py文件运行测试用例输出报告

import pytest

import os

if __name__ == '__main__':

pytest.main(["-sq", "--alluredir", "./allure-results"])

os.system("allure generate ./allure-results/ -o ./allure-report/ --clean")

4dd23b7e1565

image.png

备注:运行run.py,使用自动查找所有的测试类和方法,生成结果文件存在allure-results文件夹下,allure generate将结果输出为html报告,所以在allure-report文件夹下会有index.html文件,打开文件后可生成报告

五.报告展示

4dd23b7e1565

image.png

4dd23b7e1565

image.png


版权声明:本文为weixin_28759829原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。