Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytest.jsp使用错误的异常引发传递_Python_Unit Testing_Testing_Automated Tests_Pytest - Fatal编程技术网

Python pytest.jsp使用错误的异常引发传递

Python pytest.jsp使用错误的异常引发传递,python,unit-testing,testing,automated-tests,pytest,Python,Unit Testing,Testing,Automated Tests,Pytest,在下面的示例中,当expecting=NotImplementedError时,我希望测试失败 import pytest def fun(): raise ValueError() @pytest.mark.parametrize("expecting", [ (ValueError), (NotImplementedError) ]) def test_something( expecting): with pytest.raises(ValueError)

在下面的示例中,当
expecting
=
NotImplementedError
时,我希望测试失败

import pytest
def fun():
    raise ValueError()

@pytest.mark.parametrize("expecting", [
    (ValueError),
    (NotImplementedError)
])
def test_something( expecting):
    with pytest.raises(ValueError):
        fun()
但是,相反,它通过了:

test_something[ValueError] PASSED
test_something[NotImplementedError] PASSED

为什么会出现这种行为,正确的用法是什么?

您的测试没有对
进行任何处理。您使用pytest.raises(ValueError)编写了
,因此pytest总是在寻找
ValueError
,这就是
fun()
引发的问题。也许你是想用pytest.raises编写
(期望):
而不是?

谢谢,我完全错过了。。我一直在关注pytest的例子——这个社区可能会很残酷!