Bird
0
0

How do you correctly declare a pytest fixture that runs once per module?

easy📝 Syntax Q3 of 15
PyTest - Fixtures
How do you correctly declare a pytest fixture that runs once per module?
A@pytest.fixture(scope='class') def my_fixture(): pass
B@pytest.fixture(scope='session') def my_fixture(): pass
C@pytest.fixture(scope='function') def my_fixture(): pass
D@pytest.fixture(scope='module') def my_fixture(): pass
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixture scopes

    The module scope means the fixture is set up once per module.
  2. Step 2: Check syntax

    The correct syntax is @pytest.fixture(scope='module') before the fixture function.
  3. Final Answer:

    @pytest.fixture(scope='module') -> Option D
  4. Quick Check:

    Fixture scope 'module' runs once per module [OK]
Quick Trick: Use scope='module' to run fixture once per module [OK]
Common Mistakes:
MISTAKES
  • Using 'session' scope when module scope is needed
  • Omitting the scope parameter defaults to 'function'
  • Confusing 'class' scope with 'module' scope

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes