Bird
0
0

What will be the outcome when running this pytest code?

medium📝 Predict Output Q5 of 15
PyTest - Markers
What will be the outcome when running this pytest code?
import pytest

@pytest.mark.xfail
def test_example():
    assert 3 > 5
AThe test will be reported as xfailed (expected failure) and not cause the suite to fail
BThe test will pass normally
CThe test will be skipped
DThe test will fail and cause the test suite to fail
Step-by-Step Solution
Solution:
  1. Step 1: Understand xfail marker

    The @pytest.mark.xfail marker marks a test as expected to fail.
  2. Step 2: Analyze the assertion

    The assertion 3 > 5 is false, so the test would normally fail.
  3. Step 3: Effect of xfail

    Since the test is expected to fail, pytest reports it as 'xfail' and does not count it as a failure in the test suite.
  4. Final Answer:

    The test will be reported as xfailed (expected failure) and not cause the suite to fail -> Option A
  5. Quick Check:

    xfail marks expected failures [OK]
Quick Trick: xfail marks tests expected to fail without failing suite [OK]
Common Mistakes:
MISTAKES
  • Assuming xfail tests cause suite failure
  • Confusing xfail with skip
  • Expecting xfail tests to pass

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes