Bird
0
0

Which of the following is TRUE about a test marked with @pytest.mark.xfail(strict=True)?

easy🧠 Conceptual Q2 of 15
PyTest - Markers
Which of the following is TRUE about a test marked with @pytest.mark.xfail(strict=True)?
AThe test will always pass regardless of the code
BThe test will be skipped and not executed
CIf the test unexpectedly passes, pytest will mark the test suite as failed
DThe test will run twice to confirm failure
Step-by-Step Solution
Solution:
  1. Step 1: Understand strict=True behavior

    When strict=True is set, pytest expects the test to fail. If it passes, this is unexpected and pytest treats it as a failure.
  2. Step 2: Effect on test suite

    This helps catch cases where a bug is fixed but the test is still marked xfail, prompting test update.
  3. Final Answer:

    If the test unexpectedly passes, pytest will mark the test suite as failed -> Option C
  4. Quick Check:

    strict=True means unexpected pass fails suite [OK]
Quick Trick: strict=True fails suite if xfail test passes [OK]
Common Mistakes:
MISTAKES
  • Thinking strict=True skips the test
  • Believing strict=True forces pass
  • Confusing strict=True with running test twice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes