Bird
0
0

You want to share a fixture that provides a temporary directory path to all tests in a project. Where should you place this fixture and why?

hard🚀 Application Q8 of 15
PyTest - Test Organization
You want to share a fixture that provides a temporary directory path to all tests in a project. Where should you place this fixture and why?
AIn a separate Python module outside the test folders
BIn <code>conftest.py</code> at the root test folder to share it across all tests
CInside each test file that needs it to avoid conflicts
DDirectly inside pytest.ini configuration file
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixture sharing scope

    Placing a fixture in conftest.py at the root test folder makes it available to all tests in subfolders automatically.
  2. Step 2: Evaluate options for sharing

    In conftest.py at the root test folder to share it across all tests correctly places the fixture in conftest.py for project-wide sharing. Others limit scope or are invalid.
  3. Final Answer:

    In conftest.py at the root test folder to share it across all tests -> Option B
  4. Quick Check:

    Root conftest.py = share fixtures project-wide [OK]
Quick Trick: Put shared fixtures in root conftest.py [OK]
Common Mistakes:
MISTAKES
  • Duplicating fixtures in each test file
  • Placing fixtures outside test folders
  • Trying to configure fixtures in pytest.ini

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes