Tests often need the same starting point. A test fixture provides that setup in one reusable place. In pytest, decorate a function with @pytest.fixture, then name it as a test parameter. Pytest calls the fixture and passes its returned value to the test. section 11.3.2
Give backend tests a ready-to-use instance
A backend fixture returns Backend("test_api_key"). Any test with a backend parameter receives that instance. The dummy key is enough because the unit test separately patches requests.get and supplies a mock API response; it makes no real API call. section 11.3.2
@pytest.fixture
def setup_app():
at = AppTest.from_file("frontend.py")
at.secrets["api_key"] = "test_api_key"
return at
The setup_app fixture creates a runnable Streamlit AppTest and puts a test API key in its secrets. Frontend tests receive it by declaring a setup_app parameter. section 11.4.1
Keep setup and isolation distinct: the fixture supplies the configured object, while a mock replaces an external dependency. These examples show setup through returned values, not teardown. section 11.3.2 section 11.4.1









