6) Test AWS S3 and boto3
Mock the boto3 client or resource instead of calling real AWS in unit tests.
Hands-on Tutorial
Learn a simple step-by-step approach for testing AWS S3, Azure Blob Storage, REST APIs, Boto clients, PostgreSQL code, and Temporal Python apps. This page focuses on practical structure, small examples, setup tips, and easy scripts so a new developer can get working quickly.
The easiest way to test cloud and integration-heavy Python apps is to keep business logic separate from service SDK calls. That lets you mock the SDK layer and test your own logic first, then add a small number of integration tests later.
Wrap boto3, Azure SDK, requests, psycopg, and Temporal client code in small classes or functions.
Use unittest.mock.patch or pytest monkeypatch at the place your code imports the dependency.
Check returned values, raised exceptions, retry logic, SQL parameters, headers, and method calls.
Use real services only for key end-to-end paths, not every single unit test.
A clean structure makes testing much easier.
Write code so the external dependency is easy to replace in tests.
Mock the boto3 client or resource instead of calling real AWS in unit tests.
Create a small wrapper and patch BlobServiceClient where your module imports it.
Mock requests.get, requests.post, or a Session object. Check URL, headers, payload, timeout, and error handling.
Mock the psycopg connection and cursor for unit tests. Keep SQL parameters separate and assert execute calls.
Separate workflow logic, activities, and client startup. Mock activity dependencies for unit tests and use Temporal's test tools for deeper tests.
Fixtures help centralize setup like config, fake environment variables, reusable mock data, and sample payloads.
Learn pytest discovery, asserts, fixtures, and running tests from shell scripts.
Practice unittest.mock patch, Mock, MagicMock, and AsyncMock on REST and SDK wrappers.
Add Postgres and cloud storage tests. Assert SQL statements, request payloads, and error handling.
Add Temporal tests. Start with activity logic, then worker and workflow integration tests.
These are the main links you will want open while learning and building tests.