24、pytest通过xfail将测试函数标记为预期失败

官方实例

python 复制代码
# content of test_xfail.py
import pytest
import sys

@pytest.mark.xfail
def test_function():
    print("test_function was invoked.")
    
    
def valid_config():
    return False
    
def test_function_02():
    if not valid_config():
        pytest.xfail("failing configuration (but should work)")

解读与实操

你可以使用xfail标记来表示你希望测试失败。

测试将运行,但失败时不会报告回溯。相反,终端报告将会在"预期失败(XFAIL)或"意外通过"(XPASS)部分中列出来,或者,你也可以在测试或其它setup函数中强制将测试标记为XFAIL。

场景应用

使用reason参数,标记失败原因。查看测试报告时将更直观。

相关推荐
XXX-1710 小时前
1.pytest基础知识(默认的测试用例的规则以及基础应用)
软件测试·pytest
Mavis先生1 天前
PyTest装饰器
pytest
神即道 道法自然 如来4 天前
Python+Pytest框架,“main_run.py文件怎么编写“?
java·python·pytest
___Dream5 天前
【项目一】基于pytest的自动化测试框架———解读requests模块
python·计算机网络·pytest
ccy加油呀7 天前
pytest 接口测试
android·pytest
云泽野9 天前
一篇文章了解Pytest单元测试框架
服务器·单元测试·pytest
___Dream9 天前
【项目一】基于pytest的自动化测试框架day1
pytest
这不巧了10 天前
Faker在pytest中的应用
python·自动化·pytest
测试界的海飞丝10 天前
pytest运行方式及前置后置封装详解
开发语言·selenium·单元测试·pytest
什么时候才能变强11 天前
Pytest-@pytest.fixture夹具篇(一)
pytest