FakeCloud Testing for AWS Backend
The S3 backend's integration tests run against FakeCloud,
a local AWS emulator, using the shared test setup in netherframe.testing.fakecloud
(see FakeCloud Tests).
Running
cd backends/netherframe.backends.aws
uv run pytest tests --nf-use-fakecloud
# or: uv run poe test-backends-aws-fakecloud
Docker is the only prerequisite. The run starts the shared FakeCloud container (or joins one
that is already running) and stops it when the last test process using it finishes. Without
--nf-use-fakecloud the FakeCloud tests are skipped and only the mocked tests run.
Test Categories
- Unit tests (mocked):
test_s3_backend.py(TestS3Backend),test_s3_backend_bootstrap.py, the in-memory half oftest_s3_backend_contract.py - FakeCloud integration tests:
test_s3_backend_fakecloud.py,test_s3_backend_fakecloud_simple.py,test_s3_backend.py::TestS3BackendIntegration,test_s3_backend_state_inspection.py::TestS3BackendStateInspectionFakeCloudandtest_s3_backend_contract.py::TestS3BackendFakeCloudContract
Writing FakeCloud Tests
Every test gets its own AWS account in FakeCloud, so tests can use fixed, readable names and run in parallel. Request one of these fixtures:
fakecloud_account: the test's account;fakecloud_account.client("s3")is a boto3 client in its3_test_resources: a state bucket and lock table created in that account ({"bucket_name": ..., "table_name": ...})
def test_new_feature(s3_test_resources, fakecloud_account):
s3 = fakecloud_account.client("s3")
s3.put_object(Bucket=s3_test_resources["bucket_name"], Key="state.tfstate", Body=b"{}")
The account is reset after the test, so no cleanup is needed. S3 bucket names are unique across accounts (as in AWS), which is why the state bucket is named with the account id.