Bird
0
0

What is the main purpose of using @pytest.mark.xfail in a test?

easy🧠 Conceptual Q11 of 15
PyTest - Markers
What is the main purpose of using @pytest.mark.xfail in a test?
ATo mark tests that are expected to fail due to known issues
BTo skip tests that are not ready to run
CTo mark tests that should always pass
DTo run tests multiple times automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of @pytest.mark.xfail

    This decorator is used to mark tests that are expected to fail because of known bugs or unfinished features.
  2. Step 2: Differentiate from other decorators

    Unlike skipping tests, xfail runs the test but expects failure. It does not mark tests to always pass or run multiple times.
  3. Final Answer:

    To mark tests that are expected to fail due to known issues -> Option A
  4. Quick Check:

    @pytest.mark.xfail = expected failure [OK]
Quick Trick: xfail means test expected to fail, not skip or pass [OK]
Common Mistakes:
MISTAKES
  • Confusing xfail with skip
  • Thinking xfail forces test to pass
  • Assuming xfail reruns tests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes