Bird
0
0

What is the scope of fixtures defined in conftest.py by default?

easy🧠 Conceptual Q1 of 15
PyTest - Fixtures
What is the scope of fixtures defined in conftest.py by default?
AClass scope, shared only within a test class
BModule scope, limited to the file where defined
CFunction scope, shared across all test files in the directory tree
DSession scope, shared across all tests in the session
Step-by-Step Solution
Solution:
  1. Step 1: Understand default fixture scope

    Fixtures in pytest default to function scope unless specified otherwise.
  2. Step 2: Recognize conftest.py sharing behavior

    Fixtures in conftest.py are accessible to all tests in the directory and subdirectories, sharing the fixture at function scope.
  3. Final Answer:

    Function scope, shared across all test files in the directory tree -> Option C
  4. Quick Check:

    Default fixture scope = function [OK]
Quick Trick: Fixtures default to function scope unless overridden [OK]
Common Mistakes:
MISTAKES
  • Assuming fixtures have session scope by default
  • Thinking fixtures are limited to one module
  • Confusing class scope with default scope

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes