Testing and compatibility tooling
The testing and compatibility tooling checks that asynchronous service behavior remains aligned with botocore while it runs across supported runtimes and HTTP backends. It combines focused client checks, local service flows, reused botocore expectations, and upstream-change guards so a change is checked at both the async boundary and the compatibility boundary.
Test model
The test model moves from small behavior checks to service-level flows. Most tests use managed async clients and local service doubles, while compatibility tests reuse botocore expectations against async objects. The stubbing and test support page explains the response stubs and mock servers used by these tests.
Async execution coverage
The suite runs async behavior through AnyIO. It covers asyncio and Trio where the selected transport supports them, and it varies the HTTP backend so transport-specific behavior does not hide a shared client contract. Collection rules keep aiohttp on asyncio and allow the HTTPX path to run with both async runtimes.
The transport tests also check that blocking setup work does not run in the event loop. They verify that request settings and client-session lifetime rules keep the same meaning across supported backends. Credential tests apply the same rule to credential subprocesses by checking the async path and the synchronous worker-thread fallback needed on platforms that do not support async subprocesses.
The same test intent can expose different defects:
- An asyncio or Trio run can show incorrect task or resource lifetime behavior.
- An aiohttp or HTTPX run can show a backend mapping problem.
- A run without the optional HTTPX package confirms that aiohttp remains a complete default path.
- A platform without async subprocess support can show whether credential loading keeps a usable fallback.
References: tests/conftest.py• L75-77 tests/conftest.py• L189-217 tests/conftest.py• L718-785 tests/test_httpsession.py• L33-116 tests/…/test_credentials.py• L1753-1815 pyproject.toml• L166-200
Service behavior coverage
Service tests check client behavior against local service models instead of depending on AWS for every assertion. Moto provides service-shaped responses for common flows. A small async server provides controlled socket behavior for delayed responses, redirects, startup failure, and clean shutdown.
This split keeps normal service behavior repeatable while still making transport edge cases observable. The local server starts in its own thread and event loop, reports its bound endpoint only after startup, and reaps the thread during cleanup. Tests marked localonly identify scenarios that need a local environment or service behavior that the normal mock path does not provide.
Service tests also cover operations whose result appears after a later poll. The DynamoDB tests check that async waiters observe a table created by another task, report a bounded failure for an unknown table, and still return an active table after the create request completes. This protects the timing contract between an async operation and its waiter.
References: tests/conftest.py• L244-247 tests/conftest.py• L295-343 tests/mock_server.py• L16-103 tests/mock_server.py• L106-114 tests/test_mock_server.py• L6-52 tests/test_dynamodb.py• L38-50 tests/test_dynamodb.py• L102-131
Compatibility contract
The compatibility contract treats botocore as the reference for public client behavior, service models, events, errors, and test expectations. The async library adapts that contract instead of creating a separate service API, so checks must detect both visible behavior changes and changes in upstream objects used by the adapter.
Botocore test reuse
The copied botocore unit and functional tests exercise shared behavior with async sessions, clients, credential providers, and response objects. Their shared helpers create async sessions, reuse loaded service models, and provide HTTP-level response control through the same event paths used by the library.
These tests preserve useful botocore assumptions without requiring each test to know how async transport works. They cover session, credentials, signing, protocols, errors, retries, endpoint discovery, user-agent data, and other cross-cutting behavior at the contract level. The credential tests also keep provider selection, role and web-identity loading, SSO and process credentials, refresh behavior, account IDs, and credential caching aligned with botocore while adapting the calls to async use.
Credential refresh checks include concurrent readers and failed refreshes. They make sure one refresh result is shared safely, failed state does not leak into a later refresh, and deferred credentials load only when needed. This protects a compatibility surface that is easy to break when synchronous botocore flows become awaitable.
User-agent checks make request-scoped state visible at the wire boundary. They verify that paginator and waiter feature IDs are present on the right request, that an S3 region redirect records its feature on the redirect path, and that feature IDs do not leak between requests or concurrent tasks.
References: tests/…/__init__.py• L24-69 tests/…/__init__.py• L120-205 tests/…/helpers.py• L8-52 tests/…/conftest.py• L14-22 tests/…/test_credentials.py• L151-369 tests/…/test_credentials.py• L1753-1815 tests/…/test_credentials.py• L2049-2252 tests/…/test_useragent.py• L28-49 tests/…/test_useragent.py• L52-81 tests/…/test_useragent.py• L119-149 tests/…/test_useragent.py• L152-227
HTTP request compatibility
The HTTP session tests protect the boundary between botocore request objects and each async transport. A request can carry a read-timeout override through its context or through a request-created event. The selected backend must apply that value without changing the client-level default when no override exists.
The transport also builds blocking SSL state outside the event loop when file work is needed. It avoids that worker handoff when verification is disabled, which keeps the test contract focused on blocking work rather than forcing every setup path through a thread.
The transport must also return redirects to botocore instead of following them. Botocore can then apply service-specific behavior such as re-signing an S3 region redirect. The tests check this with both HTTP session choices and a local server that returns a temporary redirect.
The tests also keep older botocore session expectations intact. A client cannot send requests after its async context ends, while closing an HTTP session more than once remains safe and does not hide an exception raised by the caller.
References: tests/test_httpsession.py• L15-61 tests/test_httpsession.py• L64-116 tests/test_httpsession.py• L134-211 tests/test_httpsession.py• L223-241 tests/mock_server.py• L40-103
Patch drift checks
Private adaptations of botocore are protected by source digests. The drift checks fail when a guarded upstream function or class changes outside the set of versions that the library has reviewed. This turns an upstream update into an explicit compatibility decision instead of allowing a silent mismatch.
The same checks assert the supported botocore protocol parser set. When botocore adds or changes a parser, the failure points maintainers to the dependency bounds and the related async adaptation. The guarded digest list records which upstream function and class versions the library has reviewed.
References: tests/test_patches.py• L124-168 tests/test_patches.py• L1756-1775 pyproject.toml• L31-40
Compatibility evaluations
Compatibility evaluations check the decisions that guide botocore synchronization. They replay known dependency changes and committed drift fixtures, then compare the resulting classifications with labels such as no-port, port-required, clean, cosmetic-drift, and behavioral-drift.
The evaluations separate classification quality from tool use. One path checks whether a change needs an async port. Another checks whether an async override has drifted from botocore. A third replays the porting path against the hash guard and the default test suite. Shared helpers keep scenario parsing, async model calls, structured verdicts, and concurrent repeated runs consistent across these checks.
These checks make compatibility maintenance measurable without treating every dependency bump as a port. They also keep nested override paths and new definitions in scope, which prevents a sync from appearing clean only because the review missed a changed symbol.
References: tests/…/test_check_async_need.py• L1-25 tests/…/test_check_override_drift.py• L1-83 tests/…/test_check_porting.py• L1-124 tests/…/test_common.py• L41-53 tests/…/test_common.py• L131-212 tests/…/test_common.py• L225-255 plugins/…/check_async_need.py• L4-28 plugins/…/check_override_drift.py• L2-23 plugins/…/check_porting.py• L2-27 plugins/…/_common.py• L141-212
Test control surfaces
The test control surfaces make external state, transport choice, and client lifetime explicit. They let a test select its conditions without changing the product path that it measures.
Shared test state
The shared fixtures remove ambient AWS configuration for normal tests. They supply fixed credentials, regions, retry settings, and client lifetimes so a developer's local profile cannot change an assertion. Resource helpers create and clean up buckets, tables, topics, queues, and other service data when a test needs service-level state.
This gives unit and local integration tests a stable starting point. Tests that intentionally use a local or external environment can opt out through the existing marker rather than weakening isolation for the full suite.
References: tests/conftest.py• L53-73 tests/conftest.py• L220-247 tests/conftest.py• L295-343 tests/conftest.py• L446-502 tests/conftest.py• L549-592
Backend selection
HTTP backend selection is a test input, not a separate test system. The suite can run only aiohttp, only HTTPX, or both. Backend-dependent tests receive the selected session class through configuration, and collection skips combinations that cannot run.
The compatibility tests also verify the optional HTTPX choice. The preferred httpx2 package is used when present, while the legacy httpx package remains a tested fallback with a deprecation warning. This protects users during the backend transition without making HTTPX a required dependency.
References: tests/conftest.py• L207-217 tests/conftest.py• L708-785 tests/test_httpx_compat.py• L1-5 tests/test_httpx_compat.py• L17-71 pyproject.toml• L42-53
Async resource lifetime
The suite treats an unclosed client, socket, or unawaited coroutine as a test failure. Async clients and local servers use context boundaries so setup and cleanup happen on the right event system, including Trio runs.
The HTTP session checks extend this rule to migration-safe close behavior. A session can be closed inside its context and again after the context exits, while a user exception remains the visible failure. The local server follows the same rule by signaling shutdown and joining its worker thread during context exit.
This policy matters because a passing request can still leave a broken async system behind. Warning rules and server lifetime checks make those defects fail near their cause.
References: pyproject.toml• L186-196 tests/test_httpsession.py• L178-241 tests/mock_server.py• L56-81 tests/test_mock_server.py• L6-52
Verification flow
The verification flow checks the packaged artifact under supported dependency combinations. Continuous integration installs the test dependencies, installs the built wheel without source-tree fallback, and runs the same task used by local service tests.
The flow is:
- Build and retrieve the source distribution and wheel.
- Install the test group with the chosen Python version, AWS CRT option, and HTTPX option.
- Install aiobotocore from the wheel.
- Run the non-
localonlysuite across the selected HTTP backend. - Collect coverage for the jobs assigned to report it.
This packaging step checks that the released artifact contains the code and tests needed to validate the compatibility contract. It also keeps local poe test tasks aligned with CI rather than maintaining two test definitions.
References: .github/…/reusable-test.yml• L47-65 .github/…/reusable-test.yml• L105-130 pyproject.toml• L80-99 pyproject.toml• L203-231
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to an async adaptation of botocore must be checked against the guarded source digest and the supported botocore range.
- Changes to the HTTP transport contract must be checked with every enabled backend and with the runtime combinations that can execute each backend.
- Changes to request context fields or request-created events must be checked for consistent timeout behavior in every HTTP backend.
- Changes to redirect handling must preserve botocore ownership of redirects so service-specific re-signing still occurs.
- Changes to service models or response shapes must be checked in both the client stub path and the copied botocore tests.
- Changes to credential provider order, async primitive selection, or subprocess handling must be checked for every supported HTTP backend and platform fallback.
- Changes to refreshable credential state must preserve single-refresh behavior and clear staged state after both success and failure.
- Changes to SSL setup must preserve the boundary between blocking file work and inline setup when no file work is needed.
- Changes to test packaging or dependency groups must be checked against the wheel-installed CI path, not only an editable checkout.
- Changes to shared fixtures must preserve AWS environment isolation and the cleanup chain for created service resources.
- Changes to feature-ID registration must be checked across sequential requests and concurrent tasks so request context does not leak.
- Changes to compatibility-evaluation verdict names, scenario fields, or override discovery must preserve the shared parser and the labels used by each evaluation.
- Changes to waiter polling or delayed resource creation must preserve the race-safe behavior tested by the DynamoDB flow.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A guarded botocore object changes without a reviewed adaptation | The async patch can use an incompatible upstream contract | Source-digest checks in tests/test_patches.py |
| Botocore adds a protocol parser outside the supported set | Parser behavior can change without a matching async review | Exact parser-set check in tests/test_patches.py |
| A credential provider selects the wrong async primitive or cannot use the platform subprocess API | Credential loading can fail on a supported backend or operating system | Provider selection and synchronous subprocess fallback checks in tests/…/test_credentials.py |
| A refresh fails after staging new credential data | Stale expiry state can make later reads use invalid credentials or skip recovery | Refresh failure and concurrent-reader checks in tests/…/test_credentials.py |
| Blocking SSL setup runs in the event loop | Client creation or the first request can block other async work | Backend-specific SSL dispatch checks in tests/test_httpsession.py |
| A request-created timeout override is dropped or applied differently by a backend | A caller gets the wrong read-timeout behavior | Cross-backend request timeout checks in tests/test_httpsession.py |
| The transport follows a redirect before botocore can process it | An S3 region redirect can lose its authorization header and fail | Redirect response check in tests/test_httpsession.py with AIOServer |
| Feature IDs remain in shared context after a request or task ends | User-agent data describes the wrong operation or leaks between concurrent requests | Functional user-agent checks in tests/…/test_useragent.py |
| A test depends on a developer's AWS profile or retry settings | Local configuration changes the result or makes a test contact the wrong service | Automatic AWS environment isolation in tests/conftest.py |
| A backend is selected without its optional package | Collection or client setup fails before the intended behavior is tested | Backend availability checks in tests/conftest.py and optional groups in pyproject.toml |
| An aiohttp test is run under Trio | The transport cannot run with that async runtime | Collection-time deselection in tests/conftest.py |
| A waiter polls before a concurrently created table is ready, or its attempt limit is ignored | A valid async service flow can fail or an unknown resource can wait without a bound | DynamoDB waiter and task-group checks in tests/test_dynamodb.py |
| A client or mock server exits without cleanup, or a session close is not repeat-safe | Sockets, threads, or sessions leak into later tests, or cleanup hides the real user error | Async context managers and warning promotion in tests/mock_server.py, tests/test_httpsession.py, and pyproject.toml |
| A compatibility evaluation misses a nested override or returns an invalid verdict | A sync can skip a needed port or stop on an unusable classification | Scenario, registry, and verdict checks in tests/…/test_common.py and the evaluation tests |
Key files
| File | Why to read it |
|---|---|
| tests/conftest.py | Defines shared isolation, runtime, backend, client, resource, and collection rules. |
| tests/test_httpsession.py | Shows how transport choices, blocking SSL work, botocore request context, redirect handling, and async session lifetime are checked across backends. |
| tests/…/test_credentials.py | Shows how copied botocore credential expectations are adapted for async providers, refresh state, runtime selection, and platform fallback. |
| tests/test_dynamodb.py | Shows service state, waiter polling, bounded failure, and concurrent resource creation. |
| tests/mock_server.py | Shows how controlled async server behavior, redirect responses, startup failure, and thread cleanup support repeatable service tests. |
| aiobotocore/stub.py | Defines the botocore-compatible async response stub entry point. |
| tests/test_stubber.py | Shows the contract expected from successful and modeled error responses. |
| tests/…/__init__.py | Provides reused botocore test helpers and HTTP response controls. |
| tests/…/helpers.py | Connects botocore-style stubbed sessions to async clients. |
| tests/…/test_useragent.py | Shows how request-scoped feature IDs are checked for redirects, paginators, waiters, and concurrent tasks. |
| tests/test_patches.py | Defines the upstream drift and protocol-set checks that protect private compatibility adaptations. |
| tests/…/test_common.py | Defines shared contracts for scenario data, override discovery, verdict schemas, and model-result parsing. |
| tests/…/test_check_async_need.py | Checks how async-port classifications map to synchronization actions. |
| tests/…/test_check_override_drift.py | Checks how changed definitions are mapped to override-drift cases. |
| tests/…/test_check_porting.py | Checks prompt rendering, changed-symbol tracking, and agent-run failure handling for port replays. |
| tests/test_httpx_compat.py | Defines supported HTTPX package preference and fallback behavior. |
| .github/…/reusable-test.yml | Shows how CI validates the built package across dependency and backend variants. |
| pyproject.toml | Defines test dependencies, warning policy, pytest behavior, and tasks used by CI. |