pytest之allure测试报告02:allure具体使用方法

一、allure包含的方法

二、allure使用教程

(1)用例中写入allure方法

复制代码
@allure.epic("数据进制项目epic")
@allure.feature("手机号模块feature")
class TestMobile:
    @allure.story("杭州的手机号story")
    @allure.title("测试手机号归属地title")
    @allure.testcase("http://www.baidu.com", name="接口地址testcase")
    @allure.issue("http://www.baidu.com", name="缺陷地址issue")
    @allure.link("http://www.baidu.com", name="链接地址link")
    @allure.description("当前手机号是13456755448,归属地是杭州的description")
    @allure.step("先进性归属地的操作step")
    @allure.severity("critical")
    def test_mobile(self):
        param = base_data.read_data()["mobile_belong"]
        result = mobile_query(param)
        assert result.body['status'] == 0
        assert result.body['msg'] == "ok"
        assert result.body['result']["shouji"] == "13456755448"
        assert result.body['result']["province"] == "浙江"
        assert result.body['result']["city"] == "杭州"
        assert result.body['result']["company"] == "中国移动"
        assert result.body['result']["cardtype"] is None
        assert result.body['result']["areacode"] == "0571"

(2)生成报告

1)配置pytest.ini。

写入 addopts: -vs --alluredir ./report。./代表报告生成在当前文件的根目录,report即为生成目录文件夹的名称。

代码中点击三角运行符号后:如下生成的报告位置:

2)终端执行生成生成根目录report:会在整个项目的根目录下生成report。

pytest 需要执行的文件的绝对路径

3)控制台输入allure generate allure-report 同样也能项目根目录中生成报告。

(3)打开/运行报告

打开根目录下的报告:

1)allure serve ./report

2)allure open allure-report 。对应打开第二步第三种方法生成的report

打开测试用例文件夹下的report:

如下运行case_optimize_class文件后,在test_case_optimize文件夹下生成report

选中该report右键,复制report的绝对路径:

终端输入report绝对地址运行

生成报告页面如下:

左下角可切换中英文。点击特性场景--数据进制项目epic可下钻查看:

关注左侧和右侧相对应展示(1)代码编写配置的内容。

相关推荐
西游音月1 天前
(2)pytest+Selenium自动化测试-环境准备
selenium·测试工具·pytest
我的xiaodoujiao1 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 23--数据驱动--参数化处理 Yaml 文件
python·学习·测试工具·pytest
我的xiaodoujiao4 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 22--数据驱动--参数化处理 Json 文件
python·学习·测试工具·pytest
胜天半月子5 天前
Python自动化测试 | 快速认识并了解pytest的基本使用
服务器·python·pytest
北珣.9 天前
自动化框架pytest基础
自动化·pytest
程序员杰哥10 天前
Pytest之收集用例规则与运行指定用例
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
学习3人组10 天前
Python + requests + pytest + allure + Jenkins 构建完整的接口自动化测试框架
python·jenkins·pytest
shao91851613 天前
Gradio全解14——使用Gradio构建MCP的服务器与客户端(4)——Python包命令:uv与uvx实战
pytest·uv·1024程序员节·npx·uvx·uv pip·ruff
我的xiaodoujiao14 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 20--PO(POM) 设计模式和用例撰写
python·学习·测试工具·设计模式·pytest
sky0Lan15 天前
一个类似 pytest 的 html 报告
android·html·pytest