Skip to main content
 首页 » 编程设计

python之在 py.test 中,当我明确跳过标记为 xfail 的测试时,如何将其报告为 'skipped' 而不是 'xfailed'

2025年05月04日23itcoder

我有一个标记为 xfail 的 py.test 测试函数:

@pytest.mark.xfail 
def test_that_fails(): 
    assert 1 == 2 

在我的 pytest_runtest_setup() Hook 中,我明确跳过了这个测试:

def pytest_runtest_setup (item): 
    pytest.skip ('Skipping this test') 

当我运行 py.test 时,它报告测试失败:

tests.py x 
 
========================== 1 xfailed in 1.69 seconds =========================== 

如何让 py.test 将此测试报告为已跳过?

我好像在问,“我怎样才能在我的 pytest_runtest_setup() Hook 中从这个测试中删除 xfail 标记?”

谢谢。

请您参考如下方法:

感谢错误报告:)

我同意期望 py.test 将此报告为“跳过”测试而不是 xfail 是有道理的。毕竟,如果跳过测试,则无法确定 xfail-outcome (xfail/xpass)。我刚刚解决了这个问题,您可以通过键入以下内容进行安装:

pip_install -i http://pypi.testrun.org -U pytest 
# using easy_install is fine as well 

这应该让你得到 2.2.5.dev4 与“py.test --version”并解决你的问题。它将成为下一个 pypi 版本的一部分。