Bird
0
0

What is wrong with this pytest fixture declaration?

medium📝 Debug Q7 of 15
PyTest - Fixtures
What is wrong with this pytest fixture declaration?
import pytest

@pytest.fixture(autouse=True, scope='invalid')
def setup():
    pass
AInvalid scope value causes pytest to raise an error
Bautouse cannot be combined with scope
CFixture function must have a return statement
DFixture name cannot be 'setup'
Step-by-Step Solution
Solution:
  1. Step 1: Check valid scope values

    pytest supports only 'function', 'class', 'module', and 'session' as scope values.
  2. Step 2: Analyze given scope

    'invalid' is not a valid scope, so pytest will raise a configuration error.
  3. Final Answer:

    Invalid scope value causes pytest to raise an error -> Option A
  4. Quick Check:

    Fixture scope must be valid string [OK]
Quick Trick: Use only valid scope strings: function, class, module, session [OK]
Common Mistakes:
MISTAKES
  • Using unsupported scope values
  • Thinking autouse and scope are mutually exclusive
  • Assuming fixture must return a value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes