I have a pytest test that tests several inputs against two different databases. i do it with using the parameterized mark twice:
@pytest.mark.parametrize(
"input_type",
[
pytest.param("input_1"),
pytest.param("input_2"),
],
)
@pytest.mark.parametrize(
"db_type",
[
pytest.param("db_type_1"),
pytest.param("db_type_2"),
],
)
What I experience is only when running input_1
with db_type_2
(for example) the test fails due to a bug
but running the same input with different db passes.
I want to mark only the input_1
and db_type_2
combination as xfail while all other combinations should not be marked as xfail.
I cant find how to do so.
If marking db_type_2
as xfail:
@pytest.mark.parametrize(
"db_type",
[
pytest.param("db_type_1"),
pytest.param("db_type_2", marks=pytest.mark.xfail)
],
)
all inputs will be xfailed and it is not the behaviour I'm looking for. Can somebody help me with this?
You could create a function that will be executed in tests collection time and handles the parametrization and the the
xfail
mark based on the dataitertools.product
allows to add another list of inputs without modifying any other part of the code except for theif
condition for allowed inputs.