参考链接 https://www.cnblogs.com/yoyoketang/p/12004145.html
一、allure-pytest 环境准备
- windows环境相关:
python+pytest+allure-pytest
- 安装allure-pytest
pip install allure-pytest
- 查看是否安装成功—>Successfully installed allure-pytest-2.8.6
二、allure命令行工具
- allure是命令行工具,需要到github上找到download到本地,解压,配置环境变量
下载地址:
https://github.com/allure-framework/allure2/releases
- 此电脑–>属性–>高级系统设置–>环境变量–>系统环境变量 path 将解压的allure到bin,
添加到path
- 查看是否生效 -->allure --version 执行结果–>2.13.6
三、用例demo
- 找一份test_allure_assert.py文件
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pytest
# 断言是写自动化测试基本最重要的一步,一个用例没有断言,就失去了自动化测试的意义了。什么是断言呢?
# 简单来讲就是实际结果和期望结果去对比,符合预期那就测试pass,不符合预期那就测试 failed
def f():
return 3
# 异常信息
'''
def test_function():
# assert f() == 3
a = f()
assert a % 2 == 0, "判断a为偶数, 当前a的值为:%s"%a
'''
# 异常断言--暂不
# 常用断言
'''
pytest里面断言实际上就是python里面的assert断言方法,常用的有以下几种
assert xx 判断xx为真
assert not xx 判断xx不为真
assert a in b 判断b包含a
assert a == b 判断a等于b
assert a != b 判断a不等于b
'''
def is_true(a):
if a > 0:
return True
else:
return False
def test_01():
# 断言为真
a = 5
b = -1
assert is_true(a)
assert not is_true(b)
print "test_01()"
def test_02():
# b in a
a = "hello"
b = "hello aaaa"
assert a in b
print "test_02()"
def test_03():
# 相等
a = "ttt"
b = "ttt"
assert a == b
print "test_03()"
def test_04():
# 不等
a = "tt1"
b = "tt2"
assert a != b
print "test_04()"
if __name__ == "__main__":
pytest.main(["-s", "assert.py"])
- 运行用例
cd 切换到文件所在的目录文件,命令执行
pytest --alluredir ./report/allure_raw
-
插曲:
a. [出现报错:(如果报错:AttributeError: module ‘allure’ has no attribute ‘severity_level’)
原因:allure-pytest 和 pytest-allure-adaptor 不能同时存在,卸载pytest-allure-adaptor
pip uninstall pytest-allure-adaptor]b. 执行完成后,\report\allure_raw 出现原始文件,不能打开成html文件
- 打开html的报告需要启动allure服务,启动命令如下
allure serve report/allure_raw
这篇博客介绍了如何在Python环境下配置pytest与allure,包括allure-pytest的安装,allure命令行工具的下载与环境变量配置,以及测试用例的执行和生成测试报告的过程。遇到的问题如模块冲突也给出了解决方法。
846

被折叠的 条评论
为什么被折叠?



