Complete worked example
python
import pytest
@pytest.fixture(scope="module")
def supported():
return ("python", "sql")
@pytest.fixture
def skills(supported):
return list(supported)
def test_initial_skills(skills):
assert skills == ["python", "sql"]
def test_add_owned_skill(skills):
skills.append("pytest")
assert skills == ["python", "sql", "pytest"]- Reasoning
- The module-scoped fixture returns an immutable tuple of supported skills. The function-scoped fixture makes a new list from that tuple for each test. Tests can append to their owned list without changing the shared baseline. This separates reusable configuration from mutable work. A broader-scoped fixture cannot simply depend on a narrower-scoped fixture whose lifetime cannot satisfy it. A ScopeMismatch is a setup error, not a product assertion failure. Design the dependency graph from stable outer resources toward per-test state.