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 failClick to reveal answer
What does
@pytest.mark.xfail indicate about a test?✗ Incorrect
@pytest.mark.xfail marks a test as expected to fail due to known issues.
If a test marked with
@pytest.mark.xfail passes, how does pytest report it by default?✗ Incorrect
Pytest reports it as an unexpected pass because it was expected to fail.
What does adding
strict=True to @pytest.mark.xfail do?✗ Incorrect
Strict mode makes pytest fail the suite if an expected failure test passes unexpectedly.
Which of these is a good reason to use
@pytest.mark.xfail?✗ Incorrect
It helps track known bugs while allowing the test suite to run smoothly.
What happens if you do not mark a failing test with
@pytest.mark.xfail?✗ Incorrect
Unmarked failing tests cause the test suite to fail.
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.