pytest: pytest.xfail should work like pytest.mark.xfail

pytest.xfail should do exactly what pytest.mark.xfail does. pytest.xfail acts like pytest.skip for no good reason. pytest.xfail should let the test run then mark it as XFAIL or XPASS.

The current pytest.xfail already exists as pytest.fail and new delayed pytest.xfail should developed in place.

https://github.com/pytest-dev/pytest/issues/7060 https://github.com/pytest-dev/pytest/issues/810

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 16 (8 by maintainers)

Most upvoted comments

This can be accomplished via the request fixture. I don’t know why pytest.xfail doesn’t do the same, but I also don’t understand pytest internals. Minimal example:

@pytest.mark.parametrize("arg", [1, 2, 3, 4])
def test_foo(request, arg):
    if arg == 2 or arg == 3:
        request.applymarker(pytest.mark.xfail)
    assert arg in (1, 2)

1 passes, 2 fails (xpass strict), 3 xfails, and 4 fails.

Thanks for looking it up

I Strongly prefer the declarative way as it implies the Metadata is available after collection