moto-ext

raw JSON →
5.1.33 verified Mon Apr 27 auth: no python

moto-ext is an extension of the moto library for mocking AWS services in tests. It provides additional AWS service mocks not included in the core moto package. Current version 5.1.33, requires Python >=3.9. Released as part of the moto ecosystem.

pip install moto-ext
error ImportError: cannot import name 'mock_aws' from 'moto'
cause moto-ext is not installed, or an older version of moto is installed.
fix
Run 'pip install moto-ext' to install the latest version.
error ModuleNotFoundError: No module named 'moto_ext'
cause Attempting to import from 'moto_ext' directly, but the import path is 'moto'.
fix
Use 'import moto' or 'from moto import mock_aws' instead.
error AttributeError: module 'moto' has no attribute 'extensions'
cause Trying to import a submodule that does not exist; moto-ext mocks are fully integrated into the 'moto' namespace.
fix
Access mocks directly via 'moto' (e.g., from moto import mock_sns).
breaking moto-ext is the successor to moto (the original package) for extended AWS mocks. The package name changed from 'moto' to 'moto-ext', but the import path remains 'moto'. Ensure you have installed 'moto-ext' and not just 'moto' to access additional mocks.
fix Install 'moto-ext' via pip: pip install moto-ext.
gotcha Do not import directly from 'moto_ext'. The correct import path is 'moto' (e.g., from moto import mock_aws). moto-ext adds extra mocks to the moto namespace.
fix Use 'from moto import mock_aws' and all other imports from 'moto'.
deprecated The old package name 'moto' is deprecated. Starting from version 5.0, the package has been renamed to 'moto-ext'. Install 'moto-ext' to get updates.
fix Replace 'pip install moto' with 'pip install moto-ext'.

Basic usage: use @mock_aws decorator from moto to mock all AWS services, including those provided by moto-ext.

import boto3
from moto import mock_aws
from moto_ext import some_mock  # replace with actual mock

@mock_aws
def test_my_function():
    client = boto3.client('sns', region_name='us-east-1')
    response = client.create_topic(Name='test-topic')
    assert 'TopicArn' in response