An integration test checks whether multiple software components work correctly together. A frontend and backend may each pass unit tests while failing when connected, so integration tests exercise their interaction and, when needed, their external dependencies. section 11.2.1 section 11.5
Build integration coverage after verifying the individual pieces:
- Test the frontend and backend together while patching requests.get; this checks the application connection without relying on the live API. section 11.5.1
- Test the backend and external API together without mocking the API; load the API key from secrets.toml and call the backend directly. section 11.5.1
- Keep end-to-end tests distinct: they exercise the frontend, backend, and API together without mocks under real-world conditions. section 11.2.2
- Run integration tests repeatedly as code changes, updating broken tests or adding coverage when new behavior appears. section 11.7
Movie search integration
A Streamlit test creates an AppTest instance, supplies a test API key, mocks requests.get, enters “test movie,” and clicks the search button. It then asserts that results appear in session state and that the expected number of expanders is rendered. A second test searches the live TMDB API for “ferris bueller,” asserting that results include Ferris Bueller’s Day Off from 1986.
Listing 11.9 Integration test
import pytest
from unittest.mock import patch, Mock
from mock_data import MOCK_MOVIES, MOCK_RESULTS
from streamlit.testing.v1 import AppTest
@pytest.fixture
def setup_app():
at = AppTest.from_file("frontend.py")
at.secrets["api_key"] = "test_api_key"
return at
@patch('requests.get')
def test_frontend_backend_integration(mock_get, setup_app):
mock_response = Mock()
mock_response.json.return_value = {'results': MOCK_MOVIES}
mock_get.return_value = mock_response
at = setup_app
at.run()
# Enter search query and click button
at.sidebar.text_input[0].set_value("test movie").run()
at.sidebar.button[0].click().run()
# Verify results are in session_state
assert "results" in at.session_state
assert at.session_state["results"] == MOCK_RESULTS
# Verify expanders are displayed
expected_expanders = len(MOCK_MOVIES)
actual_expanders = len(at.expander)
assert actual_expanders == expected_expanders, \
f"Expected {expected_expanders} expanders, found {actual_expanders}"
# Add more assertions as required
Use the complete listing to inspect a pytest integration test that combines AppTest-driven user interaction with a patched HTTP request. section 11.5.1






























