Bird
0
0

Consider this pytest code snippet:

medium📝 Predict Output Q13 of 15
PyTest - Markers
Consider this pytest code snippet:
@pytest.mark.xfail(strict=True)
def test_divide():
    assert 1 / 0 == 0

What will be the test result when running pytest?
ATest passes because failure is expected
BTest fails because division by zero raises an error
CTest is skipped due to xfail
DTest fails because strict=True causes failure on error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the test code

    The test asserts 1 divided by 0 equals 0, which raises a ZeroDivisionError, causing failure.
  2. Step 2: Understand xfail with strict=True

    Since failure is expected, the test is marked as xfail and will pass the test suite. strict=True only fails if the test unexpectedly passes.
  3. Final Answer:

    Test passes because failure is expected -> Option A
  4. Quick Check:

    xfail with error = pass test [OK]
Quick Trick: xfail passes if test fails; strict=True fails only if test passes [OK]
Common Mistakes:
MISTAKES
  • Thinking strict=True fails on error
  • Confusing xfail with skip
  • Expecting test to fail pytest run

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes