Replies: 1 comment
-
Meanwhile figured out one can do something along that line: # conftest
def pytest_generate_tests(metafunc):
for mark_parametrize in filter(lambda marker: marker.name == "parametrize", metafunc.definition.own_markers):
param_names = mark_parametrize.args[0].split(',')
param_values = mark_parametrize.args[1]
for param_value in param_values:
if not isinstance(param_value, list):
param_value = [param_value]
for fixture, fixture_param in zip(param_names, param_value):
if fixture == "foo" and fixture_param == 'A':
metafunc.parametrize("bar", ['X'], scope="module")
elif fixture == "foo" and fixture_param == 'B':
metafunc.parametrize("bar", ['Y'], scope="module")
# tests
@pytest.fixture(scope="module")
def bar(request):
return request.param
@pytest.fixture(scope="module")
def foo(request, bar):
return request.param, bar
@pytest.mark.parametrize("foo", ["A"], indirect=True)
def test_1(foo):
assert foo == ("A", "X")
@pytest.mark.parametrize("foo", ["B"], indirect=True)
def test_2(foo):
assert foo == ("B", "Y") It solves my contrived example, but is of course very limited in general. It only handles parameters given via Still searching for a better idea... anybody? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to arrange some external resources foo and bar (say hardware) by means of fixtures. Consider these constraints
To my understanding, mutual exclusivity (state A or B, state X or Z), can be expressed with indirectly parameterized fixtures:
But now I've no idea how to express a conditional dependency from
foo
on abar
in certain state, determined by value offoo
'srequest.param
, and still static enough to allow pytest to optimize test order based on that dependency in itsreorder_items_atscope
?Is it possible? As I'm afraid the answer is going to be "currently no", how would you handle the above situation in best effort?
Beta Was this translation helpful? Give feedback.
All reactions