Bird
0
0

Why should you avoid importing fixtures from conftest.py directly in test files?

hard🧠 Conceptual Q10 of 15
PyTest - Fixtures
Why should you avoid importing fixtures from conftest.py directly in test files?
Apytest automatically discovers fixtures in conftest.py, direct import can cause conflicts
BFixtures in conftest.py are private and cannot be imported
CImporting fixtures causes them to run twice
DDirect import disables fixture scope control
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest fixture discovery

    pytest automatically finds fixtures in conftest.py without imports.
  2. Step 2: Recognize import side effects

    Importing fixtures manually can cause unexpected behavior or conflicts with pytest's fixture management.
  3. Final Answer:

    pytest automatically discovers fixtures in conftest.py, direct import can cause conflicts -> Option A
  4. Quick Check:

    Avoid importing conftest fixtures; pytest finds them automatically [OK]
Quick Trick: Never import conftest fixtures; pytest auto-discovers them [OK]
Common Mistakes:
MISTAKES
  • Importing fixtures causing duplicate fixture instances
  • Thinking fixtures must be imported like normal functions
  • Believing fixture scope is affected by imports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes