Complete the code to define a pytest fixture named 'data' that returns a list.
import pytest @pytest.fixture def data(): return [1]
The fixture should return a list, so the correct answer is a list literal [1, 2, 3].
Complete the code to select a fixture dynamically based on the 'request' parameter.
import pytest @pytest.fixture def dynamic_data(request): fixture_name = 'data_' + request.param return request.getfixturevalue([1])
The variable fixture_name holds the name of the fixture to get, so it should be passed to getfixturevalue.
Fix the error in the test function to use the dynamic fixture with parameterization.
@pytest.mark.parametrize('dynamic_data', ['one', 'two'], indirect=True) def test_dynamic(dynamic_data): assert isinstance(dynamic_data, list) and len(dynamic_data) == [1]
The fixtures 'data_one' and 'data_two' return lists of length 3, so the assertion checks for length 3.
Fill both blanks to define two fixtures 'data_one' and 'data_two' returning different lists.
@pytest.fixture def data_one(): return [1] @pytest.fixture def data_two(): return [2]
The fixtures should return different lists. 'data_one' returns [1, 2, 3] and 'data_two' returns [7, 8, 9].
Fill all three blanks to create a test that uses dynamic fixture selection and asserts the first element.
@pytest.mark.parametrize('dynamic_data', ['one', 'two'], indirect=True) def test_first_element(dynamic_data): assert dynamic_data[[1]] == [2] and len(dynamic_data) == [3]
The first element index is 0, the first element of 'data_one' is 1, and the length of the list is 3.