pytest.xfail
and pytest.skip
as context managers
#13001
Labels
type: proposal
proposal for a new feature, often to gather opinions or design the API around the new feature
What's the problem this feature will solve?
For some reason we may expect a specific part of the test to fail or to be skipped (maybe conditionally), usually because there's a blocking issue to be resolved.
Describe the solution you'd like
We propose exposing
pytest.xfail
andpytest.skip
(or their equivalents) as context managers, just likepytest.raises
. So we may have:pytest.skip
is used for a similar purpose, only when the broken tests are not even going to be run.Alternative Solutions
We can, of course, break a single test into multiple and mark them with
@pytest.mark.xfail
and@pytest.mark.skip
. This is less favorable because tests may be organized and can share some setup codes (which may not be exposed by fixture). Most importantly, we may want the test to early fail before it ever touches thewith pytest.xfail
block, and this is not achievable without the help of plugins likepytest-dependency
.Additional context
We would also like to see
strict=
argument in the currentpytest.xfail
.The text was updated successfully, but these errors were encountered: