0
0
PyTesttesting~5 mins

@pytest.mark.xfail for expected failures - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does @pytest.mark.xfail do in a pytest test?
It marks a test as an expected failure. If the test fails, pytest reports it as an expected failure, not a test failure.
Click to reveal answer
intermediate
How does pytest report a test marked with @pytest.mark.xfail when it actually passes?
Pytest reports it as an unexpected pass because the test was expected to fail but passed.
Click to reveal answer
beginner
Why would you use @pytest.mark.xfail in your test suite?
To acknowledge known bugs or incomplete features without failing the whole test suite, allowing progress while tracking issues.
Click to reveal answer
intermediate
What happens if a test marked with @pytest.mark.xfail(strict=True) unexpectedly passes?
The test suite will fail because strict mode treats unexpected passes as errors.
Click to reveal answer
beginner
Show a simple example of using @pytest.mark.xfail in a test function.
import pytest

@pytest.mark.xfail
def test_example():
    assert 1 == 2  # This test is expected to fail
Click to reveal answer
What does @pytest.mark.xfail indicate about a test?
AThe test should be skipped
BThe test is expected to fail
CThe test must always pass
DThe test is ignored
If a test marked with @pytest.mark.xfail passes, how does pytest report it by default?
AUnexpected pass
BPass
CFail
DSkipped
What does adding strict=True to @pytest.mark.xfail do?
AFails the test suite if the test unexpectedly passes
BRuns the test twice
CIgnores the test result
DSkips the test
Which of these is a good reason to use @pytest.mark.xfail?
ATo hide all test failures
BTo speed up test execution
CTo skip tests permanently
DTo document known bugs without failing the suite
What happens if you do not mark a failing test with @pytest.mark.xfail?
AThe test passes anyway
BThe test is ignored
CThe test suite fails
DThe test is skipped
Explain how @pytest.mark.xfail helps manage tests with known bugs.
Think about how you handle bugs that are not fixed yet but don't want to block progress.
You got /4 concepts.
    Describe the difference between @pytest.mark.xfail with and without strict=True.
    Consider how strict mode changes the test suite behavior when a test passes unexpectedly.
    You got /3 concepts.