【发布时间】:2017-01-30 12:54:08
【问题描述】:
我有一个函数会在满足某些条件时引发 TypeError。
def myfunc(..args here...):
...
raise TypeError('Message')
我想使用 pytest 参数化测试这条消息。
但是,因为我正在使用其他参数,所以我也希望有这样的设置:
testdata = [
(..args here..., 'Message'), # Message is the expected output
]
@pytest.mark.parametrize(
"..args here..., expected_output", testdata)
def test_myfunc(
..args here..., expected_output):
obs = myfunc()
assert obs == expected_output
简单地将Message 作为参数化测试数据中的预期输出,给我一个失败的测试。
【问题讨论】: