Bird
0
0

Identify the mistake in the following pytest code snippet:

medium📝 Debug Q7 of 15
PyTest - Fixtures
Identify the mistake in the following pytest code snippet:
import pytest

@pytest.fixture
def config():
    return {"mode": "test"}

def test_config():
    assert config["mode"] == "test"
AThe fixture must be decorated with @pytest.mark.usefixtures
BThe fixture should return a string, not a dictionary
CThe test function should call config() instead of using it as a dictionary
DThe fixture 'config' is not passed as a parameter to the test function
Step-by-Step Solution
Solution:
  1. Step 1: Analyze fixture usage

    The fixture 'config' returns a dictionary, but the test function tries to access it directly without receiving it as an argument.
  2. Step 2: Understand pytest fixture injection

    Fixtures must be declared as parameters in test functions to receive their return values.
  3. Final Answer:

    The fixture 'config' is not passed as a parameter to the test function -> Option D
  4. Quick Check:

    Fixture must be function argument to access its value [OK]
Quick Trick: Pass fixture as test function parameter [OK]
Common Mistakes:
MISTAKES
  • Accessing fixture name directly without parameter
  • Calling fixture as a function inside test
  • Misusing @pytest.mark.usefixtures decorator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes