Bird
0
0

Analyze this pytest test:

medium📝 Debug Q7 of 15
PyTest - Markers
Analyze this pytest test:
@pytest.mark.xfail(strict=True)
def test_membership():
    assert 'x' in ['a', 'b', 'c']

What will pytest report when this test runs?
ATest fails and is reported as XFAIL
BTest passes and is reported as XPASS, causing test suite failure
CTest is skipped
DTest passes normally without any special mark
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate assertion

    The assertion 'x' in ['a', 'b', 'c'] is false, so test fails.
  2. Step 2: Check actual test result

    Wait, the assertion is false, so test fails. But the question is about what pytest reports.
  3. Step 3: Re-examine assertion

    Actually, the assertion is false, so test fails as expected.
  4. Step 4: Confirm strict=True effect

    Since test fails, pytest reports XFAIL.
  5. Final Answer:

    Test fails and is reported as XFAIL -> Option A
  6. Quick Check:

    Failing xfail test reports XFAIL [OK]
Quick Trick: Failing xfail test reports XFAIL, strict=True affects XPASS only [OK]
Common Mistakes:
MISTAKES
  • Assuming test passes when assertion is false
  • Confusing XPASS with XFAIL
  • Misunderstanding strict=True behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes