Bird
0
0

What is the main advantage of using conftest.py in a pytest testing suite?

easy🧠 Conceptual Q1 of 15
PyTest - Test Organization
What is the main advantage of using conftest.py in a pytest testing suite?
ATo define fixtures that can be shared across multiple test files without importing
BTo store test data in JSON format
CTo configure logging settings for pytest
DTo write test cases directly
Step-by-Step Solution
Solution:
  1. Step 1: Understand conftest.py role

    conftest.py is used to define fixtures and hooks that are automatically discovered by pytest.
  2. Step 2: Identify sharing capability

    Fixtures in conftest.py are accessible to all test files in the directory tree without explicit imports.
  3. Final Answer:

    To define fixtures that can be shared across multiple test files without importing -> Option A
  4. Quick Check:

    Sharing fixtures without imports [OK]
Quick Trick: Fixtures in conftest.py are auto-discovered and shared [OK]
Common Mistakes:
MISTAKES
  • Thinking conftest.py is for test data storage
  • Assuming it is for logging configuration
  • Believing tests are written inside conftest.py

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes