Patching temporarily replaces a referenced dependency with a controlled substitute while a test runs. This prevents real external requests and makes responses predictable, observable, and repeatable. section 11.3.2
With unittest.mock, @patch('requests.get') supplies a mock object to the test. Configure its return value, call the backend, and verify both the result and the request arguments. section 11.3.2
A practical patched test typically:
- Creates a fake response whose json method returns predefined data. section 11.3.2
- Replaces the external request and invokes the method under test. section 11.3.2
- Checks calls, returned collections, and selected values. section 11.3.2
Testing movie search
Patch requests.get, return two predefined movies, call search_movies("test query"), and assert the expected URL parameters, result count, identifiers, and titles. Additional tests cover no results and missing poster paths. section 11.3.2
The same isolation principle applies to Streamlit frontends, while AppTest additionally simulates clicks, text entry, and inspection of rendered output. section 11.4



