Bird
0
0

What will happen when running this pytest code?

medium📝 Predict Output Q5 of 15
PyTest - Markers
What will happen when running this pytest code?
@pytest.mark.xfail(strict=True)
def test_func():
    assert 2 + 2 == 4
ATest is reported as failed because it unexpectedly passed
BTest is skipped
CTest passes normally
DTest is reported as xfailed
Step-by-Step Solution
Solution:
  1. Step 1: Analyze assertion result

    The assertion 2 + 2 == 4 is true, so test passes.
  2. Step 2: Effect of strict=True with xfail

    strict=True means if test passes unexpectedly, pytest treats it as failure.
  3. Final Answer:

    Test is reported as failed because it unexpectedly passed -> Option A
  4. Quick Check:

    strict=True fails suite on unexpected pass [OK]
Quick Trick: strict=True fails test if xfail test passes [OK]
Common Mistakes:
MISTAKES
  • Assuming test passes normally with strict=True
  • Thinking test is skipped
  • Confusing xfail with skip

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes