【发布时间】:2019-01-07 16:43:30
【问题描述】:
假设我有一个测试函数,它将参数化 record 作为 dict,其中一个值是已经定义的夹具。
例如,我们有一个夹具:
@pytest.fixture
def a_value():
return "some_value"
以及测试功能:
@pytest.mark.parametrize("record", [{"a": a_value, "other": "other_value"},
{"a": a_value, "another": "another_value"}])
def test_record(record):
do_something(record)
现在,我知道这可以通过将夹具传递给测试函数并相应地更新记录来解决,例如:
@pytest.mark.parametrize("record", [{"other": "other_value"},
{"another": "another_value"}])
def test_record(a_value, record):
record["a"] = a_value
do_something(record)
但我想知道是否有一种方法可以在没有这种“解决方法”的情况下做到这一点,当我有许多已经定义的固定装置并且我只想在传递给函数的每个参数化记录中使用它们时。
我已经检查过this question,尽管它似乎并不完全适合我的情况。从那里的答案中找不到正确的用法。
【问题讨论】:
-
谢谢@wim - 如果我理解正确,这需要我修改运行测试的注释。有没有办法通过代码做到这一点?
标签: python python-2.7 testing pytest