Test Overview
This test demonstrates how one pytest fixture can use another fixture as a dependency. It verifies that the dependent fixture correctly receives and uses the data from the base fixture.
This test demonstrates how one pytest fixture can use another fixture as a dependency. It verifies that the dependent fixture correctly receives and uses the data from the base fixture.
import pytest @pytest.fixture def base_data(): return 10 @pytest.fixture def dependent_data(base_data): return base_data * 2 def test_dependent_fixture(dependent_data): assert dependent_data == 20
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | — | PASS |
| 2 | pytest discovers test_dependent_fixture and its fixture dependencies | Test function and fixtures recognized | — | PASS |
| 3 | pytest calls base_data fixture | base_data fixture returns 10 | — | PASS |
| 4 | pytest calls dependent_data fixture with base_data=10 | dependent_data fixture returns 20 | — | PASS |
| 5 | pytest runs test_dependent_fixture with dependent_data=20 | Test function executes assertion | assert dependent_data == 20 | PASS |
| 6 | Test ends | All assertions passed | — | PASS |
import pytest
@pytest.fixture
def base():
return 10
@pytest.fixture
def add_five(base):
return base + 5
def test_sum(add_five):
assert add_five == 15
print(add_five)import pytest
@pytest.fixture
def data():
return [1, 2, 3]
@pytest.fixture
def processed_data():
data.append(4)
return datafull_config that depends on two other fixtures: base_config returning a dict {'host': 'localhost'} and auth_config returning {'user': 'admin'}. Which code correctly combines these fixtures so full_config returns {'host': 'localhost', 'user': 'admin'}?Pass the test and this pattern moves unknown