Bird
0
0

Why is it recommended to avoid importing conftest.py directly in test files?

hard🧠 Conceptual Q10 of 15
PyTest - Test Organization
Why is it recommended to avoid importing conftest.py directly in test files?
ABecause pytest automatically discovers and loads conftest.py, manual imports can cause conflicts
BBecause conftest.py is not a valid Python module
CBecause importing conftest.py slows down test execution significantly
DBecause conftest.py can only contain test functions, not fixtures
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest's conftest.py handling

    pytest automatically discovers and loads conftest.py files without imports.
  2. Step 2: Identify why manual imports are discouraged

    Manually importing conftest.py can cause conflicts or duplicate fixture definitions.
  3. Final Answer:

    Because pytest automatically discovers and loads conftest.py, manual imports can cause conflicts -> Option A
  4. Quick Check:

    Do not import conftest.py manually [OK]
Quick Trick: Never import conftest.py; pytest loads it automatically [OK]
Common Mistakes:
MISTAKES
  • Importing conftest.py manually in tests
  • Thinking conftest.py is not a Python module
  • Believing imports improve performance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes