Where are moto's limits, and what do you do about them?
AdvancedConceptTesting, services & metrics
Answer
moto implements most common operations but not every API, field or behaviour: IAM policies are not enforced by default, some timestamps are always "now" (for example snapshot StartTime), CloudWatch only returns metrics you put yourself, and eventual consistency is not simulated. Approaches:
- For time-based logic, stub the response with
unittest.mockor botocore'sStubber, or inject a clock. - Keep business logic in pure functions that take dicts, test those directly, and use moto for the API glue.
- Run a small integration suite against a real sandbox account (or LocalStack) on a schedule.
More on Testing, services & metrics
Why should automation scripts have tests at all?BeginnerHow does pytest discover and run tests?BeginnerWhy does pytest use plain `assert` instead of `assertEqual`?BeginnerWhat are pytest fixtures, and what scopes exist?IntermediateWhat built-in fixtures do you use most?IntermediateHow does `@pytest.mark.parametrize` work?Beginner