您的位置:首页 > 新闻 > 热点要闻 > 河南网络推广公司_页面设计在线_推广普通话的意义简短_青岛seo优化公司

河南网络推广公司_页面设计在线_推广普通话的意义简短_青岛seo优化公司

2025/3/11 7:00:11 来源:https://blog.csdn.net/qq_41969287/article/details/146054195  浏览:    关键词:河南网络推广公司_页面设计在线_推广普通话的意义简短_青岛seo优化公司
河南网络推广公司_页面设计在线_推广普通话的意义简短_青岛seo优化公司

Allure

  • 一、文档
  • 二、指令
  • 三、装饰器
    • 3.1 @allure.step装饰器
    • 3.2 @allure.description装饰器
    • 3.3 @allure.title装饰器

一、文档

allure文档

二、指令

1、运行测试并生成 allure 数据

pytest --alluredir=./allure_results

2、生成并打开报告

allure serve ./allure_results

三、装饰器

3.1 @allure.step装饰器

将函数或方法标记为测试步骤,并在 Allure 报告中展示步骤层级。
直接在测试方法或函数上添加 @allure.step 装饰器,并可自定义步骤名称,支持使用{}占位符。

import allure@allure.step("打开应用首页")
def open_homepage():print("-----------open--------------")pass# 使用 {} 占位符将变量嵌入步骤名称,参数自动填充。
@allure.step("输入用户名和密码: {username},{password}")
def input_username(username, password):print(f"-----------{username}--------------")pass# 步骤可以嵌套,形成清晰的逻辑层级
def test_login():open_homepage()input_username("test_user","1234")

conftest.py与@allure.step结合,显示单独的“前置/后置”树,用于配置初始化和销毁。
conftest.py:

import pytest
import allure@allure.step("step in conftest.py for setup")
def conftest_test():pass@allure.step("step in conftest.py for teardown")
def conftest_test_of_teardown():pass@pytest.fixture(autouse=True)
def fixture_with_conftest_test():conftest_test()yieldconftest_test_of_teardown()

运行结果:
在这里插入图片描述

3.2 @allure.description装饰器

为测试用例添加详细描述

1、@allure.description提供描述字符串
2、@allure.description_html添加html格式的描述
3、仅从测试方法的文档字符串获取描述

import pytest
import alluredef test_unicode_in_description():"""unicode描述使用不同的国家语言helloこんにちは你好伙计"""assert 42 == int(6 * 7)@pytest.mark.parametrize("username", ["user1", "user2"])
@allure.description("测试不同用户名的登录兼容性:username={username}")
def test_login_compatibility(username):pass@allure.description_html("""
<h1>添加html格式的描述</h1>
""")
def test_description_html():pass@allure.description("动态描述,可替换开始的描述")
def test_login_change():passallure.dynamic.description("测试用例执行完了,更改描述")

在这里插入图片描述

3.3 @allure.title装饰器

使测试标题更具可读性,标题支持占位符并支持动态替换

import pytest
import allure@allure.title("@allure.title使测试标题更具可读性,标题支持占位符并支持动态替换")
def test_with_a_title():assert 2 + 2 == 4@pytest.mark.parametrize("param1,param2,expected", [(1, 1, 2), (1, 3, 5)])
@allure.title("标题包含动态参数:{param1},{param2}")
def test_with_parametrize_title(param1, param2, expected):assert param1 + param2 == expected@allure.title("动态描述,可替换开始的描述")
def test_title_update():passallure.dynamic.title("测试用例执行完了,更改标题")

运行结果:
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com