gpt4 book ai didi

python - Pytest:将 xfail 与 raise 一起使用,测试尽管意外异常仍保持 xfailiing

转载 作者:行者123 更新时间:2023-12-01 04:48:27 24 4
gpt4 key购买 nike

我将使用装饰器将测试标记为 xfail,并为它们提供预计在应用程序的当前开发状态​​中发生的特定异常。

据我了解 http://pytest.org/latest/skipping.html 中的文档如果测试现在失败或出现不同异常的错误,则测试应该报告失败,并且没有预期的失败。

实现与我理解的不同吗?

示例:

import pytest

@pytest.mark.xfail(raises=AttributeError)
def test_xfailure():

print "Hello"

raise NotImplemented()
<小时/>

运行它:

# py.test failtest.py 
============================================================================= test session starts ==============================================================================
platform linux2 -- Python 2.6.6 -- py-1.4.26 -- pytest-2.6.0
plugins: cov, xdist, random
collected 1 items

failtest.py x

========================================================================== 1 xfailed in 0.04 seconds ===========================================================================

最佳答案

使用最新的 py.test 版本 2.6.4 解决了!抱歉...

实际问题是,这似乎是 pytest 2.6.0 中的一个错误我们使用的项目中的开发环境有点过时,我根本没有意识到 2.6.0(也在示例输出中显示)和 2.6.4 之间的次要版本差异

关于python - Pytest:将 xfail 与 raise 一起使用,测试尽管意外异常仍保持 xfailiing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28916186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com