Bird
0
0

What happens when a test marked with @pytest.mark.xfail actually passes during test execution?

easy🧠 Conceptual Q1 of 15
PyTest - Markers
What happens when a test marked with @pytest.mark.xfail actually passes during test execution?
AThe test is reported as failed
BThe test is reported as an unexpected success (XPASS)
CThe test is skipped
DThe test is reported as passed normally
Step-by-Step Solution
Solution:
  1. Step 1: Understand xfail behavior

    Tests marked with @pytest.mark.xfail are expected to fail.
  2. Step 2: Check what happens if test passes

    If such a test passes, pytest reports it as an unexpected success (XPASS).
  3. Final Answer:

    Tests marked with xfail that pass are reported as XPASS -> Option B
  4. Quick Check:

    xfail passing test = XPASS [OK]
Quick Trick: xfail passing test shows XPASS in pytest report [OK]
Common Mistakes:
MISTAKES
  • Assuming xfail tests that pass are reported as passed
  • Thinking xfail tests that pass are skipped
  • Confusing xfail with skip decorators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes