Bird
0
0

How do you correctly define a pytest fixture named config that returns a dictionary?

easy🧠 Conceptual Q3 of 15
PyTest - Fixtures
How do you correctly define a pytest fixture named config that returns a dictionary?
A@pytest.fixture\ndef config():\n return {'env': 'test'}
Bdef config():\n return {'env': 'test'}
C@pytest.test\ndef config():\n return {'env': 'test'}
D@fixture\ndef config():\n return {'env': 'test'}
Step-by-Step Solution
Solution:
  1. Step 1: Recognize fixture syntax

    Fixtures require the @pytest.fixture decorator above the function.
  2. Step 2: Check function definition

    The function should return the desired data, here a dictionary.
  3. Step 3: Validate options

    @pytest.fixture\ndef config():\n return {'env': 'test'} correctly uses @pytest.fixture and returns a dictionary.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Decorator must be @pytest.fixture exactly [OK]
Quick Trick: Use @pytest.fixture decorator to define fixtures [OK]
Common Mistakes:
MISTAKES
  • Omitting the decorator
  • Using incorrect decorator names
  • Defining fixture without return value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes