I have a Flask app that uses AWS services such as dynamodb. I want to mock these out during unit tests but I'm having trouble doing so.
Here is a minimal example that doesn't work for me:
from flask import Flask
import boto3
app = Flask(__name__)
@app.route("/")
def hello():
aws_session = boto3.session.Session()
dynamodb = aws_session.resource("dynamodb")
table = dynamodb.Table("test-table")
table.put_item(Item={
"hello": "world"
})
return "ok"
from moto import mock_dynamodb
import pytest
@pytest.fixture
def client():
with app.test_client() as client:
yield client
@mock_dynamodb
def test_response(client):
rv = client.get('/')
assert rv.data == "ok"
I'm getting an error that the resource does not exist. This means that an AWS call is in fact being made. Why isn't the call mocked out?