1

if anyone knows how do deal with the following issue:

@pytest.mark.parametrize("paramA, paramB", params_variable)
@pytest.mark.parametrize("bool", (True, False))
@pytest.mark.parametrize("size", sizes_variable)
def test_definition(paramA, paramB, boolA, boolB, size):
    assert something

Lets imagine that tests results can be like this:

FAILED test_definition[paramA_1-paramB_2-bool_true-size_4] - AssertionError: assert False

FAILED test_definition[paramA_4-paramB_6-bool_false-size_1] - AssertionError: assert False

How to wrap a specific constellation of parameters to marked them as Xfail? Is it possible?

When I put xfail to some specific parameters, I will marked all Test Cases with this parameter as Xfail - but I only want to mark specific constellation (in the case above - only two cases from a lot of)

billion points for someone who will resolve this problem

1 Answer 1

3

If you know the parameter combinations where you want to have the xfail marker, you can add the marker in pytest_collection_modifyitems based on the function name:

conftest.py

def pytest_collection_modifyitems(config, items):
    for item in items:
        if item.name in ("test_definition[paramA_1-paramB_2-bool_true-size_4]",
                         "test_definition[paramA_4-paramB_6-bool_false-size_1]"):
            item.add_marker("xfail")

This has to be done in the conftest.py in the same directory as the test, or in a directory above.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, you won 1000points. This works perfectly, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.