Bird
0
0

In pytest, what does setting a fixture's scope to class mean?

easy🧠 Conceptual Q1 of 15
PyTest - Fixtures
In pytest, what does setting a fixture's scope to class mean?
AThe fixture is created once per test class and shared among its methods.
BThe fixture is created once per test function.
CThe fixture is created once per test module.
DThe fixture is created once per test session.
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest fixture scopes

    Pytest fixtures can have scopes like function, class, module, or session, which control how often the fixture is set up.
  2. Step 2: Interpret the class scope meaning

    When scope is set to class, the fixture runs once for the entire test class and is shared by all test methods inside that class.
  3. Final Answer:

    The fixture is created once per test class and shared among its methods. -> Option A
  4. Quick Check:

    Fixture scope 'class' = once per test class [OK]
Quick Trick: Class scope means one setup per test class [OK]
Common Mistakes:
MISTAKES
  • Confusing class scope with function scope
  • Thinking class scope runs once per test function
  • Mixing up class and module scopes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes