Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
Isolate the external call behind an interface, replace it in tests with a fake or with unittest.mock patched where it is looked up, use fixtures for setup, and assert on both the result and how the dependency was called.
Unit tests should not hit the real API, because it is slow, flaky and may cost money. Passing the client as a dependency makes it easy to supply a fake in tests; otherwise mock.patch can replace it, but it must patch the name in the module that uses it, such as 'orders.service.PaymentClient', not where it was defined. pytest fixtures provide reusable setup, and parametrize covers success, declined payments, timeouts and invalid responses. Assertions check the returned result and that the client was called with the right arguments. A few separate integration or contract tests, against a sandbox or recorded responses, verify that the real API still behaves as the fake assumes.