【发布时间】:2016-12-25 00:07:51
【问题描述】:
我希望一个参数化依赖于之前的一个:
@pytest.mark.parametrize("locale_name", LOCALES)
@pytest.mark.parametrize("money_string", ["500{currency}", "500 {currency}"])
@pytest.mark.parametrize("currency", LOCALES['locale_name']['currencies'])
def test_do_stuff(locale_name, money_string, currency):
print(locale_name, money_string, currency)
这里,第三个参数化取决于第一个。
我尝试通过以下方式将其拆分:
@pytest.mark.parametrize("locale_name", LOCALES)
@pytest.mark.parametrize("money_string", ["500{currency}", "500 {currency}"])
def test_currencies(locale_name, money_string):
# locale is actually also needed as an object, cannot be taken out.
locale = LOCALES[locale_name]
@pytest.mark.parametrize("currency", locale['currencies'])
def test_inner_currencies(currency):
print("this does not run however")
但是内部代码没有运行。除了使用itertools.product 预先生成配对之外,我不确定对于这种情况我能做些什么(但这看起来很丑陋)?
请注意,我可以只有一个 for 循环,但我不会“正式”运行尽可能多的测试。
【问题讨论】:
标签: python dependencies pytest