Bird
0
0

Identify the mistake in this pytest fixture definition:

medium📝 Debug Q6 of 15
PyTest - Fixtures
Identify the mistake in this pytest fixture definition:
import pytest

@pytest.fixture(scope='sesssion')
def data_loader():
    return {'data': 123}
AThe scope value 'sesssion' is misspelled
BFixture functions cannot return data
CMissing yield statement in fixture
DFixture must be defined inside a test class
Step-by-Step Solution
Solution:
  1. Step 1: Check scope spelling

    The scope parameter is misspelled as 'sesssion' instead of 'session'.
  2. Step 2: Validate fixture return

    Fixtures can return data; returning a dictionary is valid.
  3. Step 3: Yield is optional

    Yield is used for teardown but not mandatory for simple fixtures.
  4. Step 4: Fixture location

    Fixtures can be defined outside test classes.
  5. Final Answer:

    Misspelled scope value -> Option A
  6. Quick Check:

    Scope names must be exact strings [OK]
Quick Trick: Check fixture scope spelling carefully [OK]
Common Mistakes:
MISTAKES
  • Typo in scope string causing fixture not to register
  • Assuming yield is mandatory for all fixtures
  • Thinking fixtures must be inside classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes