I have created a 'dynamic' list of parameters which I pass to parametrize.
OPTIONS = ['a', 'b', 'c']
def get_unique_pairs():
unique_list = []
for first in OPTIONS:
for second OPTIONS:
if first == second:
continue
unique_list.append({'first':first, 'second':second))
return unique_list
def some_func()
unique_pairs = get_unique_pairs()
result = []
for pair in unique_pair:
if test(pair):
continue
else:
result.append(pair)
return pair
@pytest.mark.parametrize('param', some_fnc())
def test_fnc(param):
first = param['first']
second = param['second']
Run Code Online (Sandbox Code Playgroud)
The input I wish to pass to test_fnc is [('a','b'),('a','c')...('c','b')] where the …
我有一个函数和一个测试
def foo(a):
return bar(a)
@pytest.mark.parametrize(
'number',
[1,2,3]
)
@pytest.mark.dependency
def test_foo(number):
assert foo(number) > SOME_CONST # Simplistic example, real case is more nuanced
Run Code Online (Sandbox Code Playgroud)
我正在使用 pytest 和 pytest_dependency 模块。foo是许多其他测试中使用的函数。我有一个函数,我想依赖它test_foo,下面的代码不起作用:
@pytest.mark.dependency(depends=['test_foo'])
@pytest.mark.parametrize(
'param',
itertools.permutations(['a','b','c','d','e'],2),
ids=repr,
)
def test_bar(param):
...
important_result = foo(param)
...
Run Code Online (Sandbox Code Playgroud)
理论上来说,如果test_foo失败,那么test_bar就会被跳过。但是,当我参数化 时,无论 的结果如何,都会跳过 的test_bar每个实例化。test_bartest_foo
澄清一下,此代码按预期工作(未跳过 test_bar):
@pytest.mark.dependency(depends=['test_foo'])
def test_bar():
param = some_fnc(['a', 'b'])
...
important_result = foo(param)
...
Run Code Online (Sandbox Code Playgroud)