Bird
0
0

Find the problem in this pytest fixture usage:

medium📝 Debug Q7 of 15
PyTest - Basics and Setup
Find the problem in this pytest fixture usage:
import pytest

@pytest.fixture
def sample_data():
    return [1, 2, 3]

def test_data():
    assert sample_data == [1, 2, 3]
AFixture not used as function argument in test
BFixture missing return statement
CTest function name does not start with 'test_'
DFixture decorator is misspelled
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixture usage in pytest

    Fixtures must be passed as arguments to test functions to be used.
  2. Step 2: Check test function parameters

    test_data does not accept sample_data as argument, so fixture is not used.
  3. Final Answer:

    Fixture not used as function argument in test -> Option A
  4. Quick Check:

    Fixtures must be function parameters [OK]
Quick Trick: Pass fixtures as test function arguments [OK]
Common Mistakes:
MISTAKES
  • Calling fixture directly instead of as argument
  • Forgetting to add fixture parameter in test
  • Assuming fixture decorator is incorrect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes