Bird
0
0

Find the problem in this pytest test:

medium📝 Debug Q7 of 15
PyTest - Markers
Find the problem in this pytest test:
import pytest

@pytest.mark.xfail(strict=True)
def test_bug():
    assert 1 == 1
ASyntax error due to strict=True
BTest will be marked as failed because it passed unexpectedly
CTest will be skipped
DNo problem, test runs normally
Step-by-Step Solution
Solution:
  1. Step 1: Understand xfail with strict=True

    When strict=True, if the test passes unexpectedly, pytest marks it as a failure.
  2. Step 2: Analyze test assertion

    The assertion passes, so pytest reports this as a failure due to unexpected pass.
  3. Final Answer:

    Test will be marked as failed because it passed unexpectedly -> Option B
  4. Quick Check:

    xfail strict=True fails on unexpected pass [OK]
Quick Trick: xfail strict=True fails if test passes [OK]
Common Mistakes:
MISTAKES
  • Assuming strict=True causes skip
  • Thinking no error on unexpected pass
  • Confusing strict with reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes