Complete the code to define a simple pytest fixture named sample_data.
import pytest @pytest.[1] def sample_data(): return [1, 2, 3]
The @pytest.fixture decorator marks a function as a fixture, making it reusable for test setup.
Complete the test function to use the sample_data fixture as a parameter.
def test_sum([1]): assert sum(sample_data) == 6
To use a fixture in pytest, include its name as a parameter in the test function.
Fix the error in the fixture usage by completing the code to return the correct data.
@pytest.fixture def numbers(): return [1]
The fixture should return a list, so use square brackets [] to return [1, 2, 3].
Fill both blanks to create a fixture that sets up a dictionary and a test that uses it.
@pytest.fixture def [1](): return {'name': 'Alice', 'age': 30} def test_user_info([2]): assert user['name'] == 'Alice'
The fixture is named user and the test function uses user as parameter to access the fixture data.
Fill all three blanks to create a fixture that sets up a list and a test that checks its length and content.
@pytest.fixture def [1](): return ['apple', 'banana', 'cherry'] def test_fruits([2]): assert len(fruits) == [3]
The fixture and test parameter are both named fruits. The list has 3 items, so the length is 3.