Bird
0
0

Why is it important to register custom markers in pytest.ini instead of just using them directly in test code?

hard🧠 Conceptual Q10 of 15
PyTest - Markers
Why is it important to register custom markers in pytest.ini instead of just using them directly in test code?
ATo avoid warnings and document marker usage for maintainability
BBecause pytest will not run tests with unregistered markers
CTo enable markers to change test execution order automatically
DBecause markers must be registered to be imported in test files
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest behavior with unregistered markers

    Pytest runs tests with unregistered markers but shows warnings, which can clutter output.
  2. Step 2: Recognize benefits of registration

    Registering markers documents their purpose and avoids warnings, improving code clarity and maintainability.
  3. Final Answer:

    To avoid warnings and document marker usage for maintainability -> Option A
  4. Quick Check:

    Register markers = avoid warnings + documentation [OK]
Quick Trick: Register markers to avoid warnings and improve clarity [OK]
Common Mistakes:
MISTAKES
  • Thinking pytest refuses to run unregistered markers
  • Assuming markers control test order automatically
  • Believing markers must be imported after registration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes