A. test_value should not take composed_fixture as parameter
B. composed_fixture should not return a value
C. Missing parentheses when calling base_value fixture inside composed_fixture
D. base_value fixture should be a class, not a function
Solution
Step 1: Check how base_value is used inside composed_fixture
Inside composed_fixture, value = base_value assigns the function, not its result.
Step 2: Correct usage of fixture call
Fixtures are injected by pytest, but inside another fixture you must accept them as parameters or call them properly. Here, base_value should be a parameter or called with parentheses if used directly.
Final Answer:
Missing parentheses when calling base_value fixture inside composed_fixture -> Option C
Quick Check:
Fixture call needs parentheses or parameter injection [OK]
Hint: Use fixture names as parameters, not direct calls without parentheses [OK]
Common Mistakes:
Assigning fixture function instead of calling it
Returning values incorrectly from fixtures
Misunderstanding fixture injection in tests
5. You want to create a fixture full_setup that uses two fixtures db_connection and user_data. The full_setup should return a dictionary combining both. Which code correctly composes these fixtures?
hard
A. import pytest
@pytest.fixture
def full_setup(db_connection, user_data):
return {**db_connection, **user_data}
B. import pytest
@pytest.fixture
def full_setup():
db = db_connection()
user = user_data()
return {**db, **user}
C. import pytest
@pytest.fixture
def full_setup():
return {**db_connection, **user_data}
Step 1: Understand fixture composition with parameters
Fixtures can be composed by listing dependent fixtures as parameters in the fixture function.
Step 2: Check correct dictionary merging
import pytest
@pytest.fixture
def full_setup(db_connection, user_data):
return {**db_connection, **user_data} correctly accepts both fixtures as parameters and merges their dictionaries using unpacking syntax.