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 can't mark the test based on the complete set of arguments in
pytest.mark.parametrize/pytest.param, the information about other arguments is simply not there yet. Usually I move out the postprocessing of test parameters in a separate fixture which then can alter the test based on the complete set of test arguments. Example:We have 200 tests overall; suppose we want to
xfailtests forx=3,y=15andx=8,y=1. We add a new fixturexfail_selected_spamsthat gets access to bothxandybeforetest_spamstarts and appends thexfailmarker to test instance if necessary:To register the fixture, use
pytest.mark.usefixtures:When running the tests now, we will get
198 failed, 2 xfailedresults since the two selected tests are expected to fail.