209 questions
1
vote
0
answers
51
views
Mocking boto3 client response
I am trying to build unit tests for my calls to dynamodb. I need to specify exactly what the client instance will respond with - to replicate a failure response from AWS. I can force failure responses ...
1
vote
0
answers
45
views
How to Use Moto Glue Catalog with Spark SQL for Local Testing?
I'm using Moto to mock AWS Glue for local testing with Spark. I can successfully start Moto with moto_server -p9999 and create databases and tables in Glue. However, when I try to run a Spark SQL ...
0
votes
1
answer
135
views
How to simulate AWS DynamoDB locally in python with moto 5
I want to make a class representing a dynamodb connection which I can use locally to mimic the behavior of DynamoDB without having to actually contact the AWS service.
I want to use it during ...
0
votes
1
answer
83
views
AWS Athena with python - is it possible to mock with moto while still testing the sql?
My code performs sql queries on Athena using boto3.
I want to be able to test the entire functionality, but avoiding the actual access to athena. I need the data to be fetched based on the query ...
3
votes
1
answer
251
views
How to use fake s3 bucket
I tried to use aiobotocore for async work with Ceph, but i have no access to real bucket, then i need to mock s3 bucket to create a fake one
I'm trying to use moto but it anyway want to connect a real ...
0
votes
1
answer
154
views
Defining AWS/boto3 clients and resources outside of functions with unit tests
I am writing some unit tests using pytest for some functions that are called using AWS Lambda. I am using boto3 to interact with AWS, and I'm mocking using moto. Where I am using a resource or client ...
0
votes
0
answers
182
views
Using AWS Moto with Python mock to write unit tests
I am working with a codebase that doesn't have any tests setup. I am trying to add some tests and currently have the below test class test_main.py
from unittest import TestCase
from moto import ...
0
votes
0
answers
73
views
Why is it that when I try to use moto to a Bazel repository I get errors related to `_cffi_backend` being missing?
At work I'm currently working on a Bazel app/repository that contains tools for dealing with AWS. I recently created a tool that deals with some AWS resources in Python (a lambda that interacts with ...
1
vote
1
answer
1k
views
Unit Testing AWS Lambda function for DynamoDB using moto 5.x.x
In the latest moto version @mock_dynamodb and @mock_dynamodb2 are depricated and removed. Can someone please share an example of mocking and unit testing dynamodb operation from AWS Lambda using moto. ...
0
votes
1
answer
188
views
coroutine was never awaited when running my test functions with pytest-asyncio and moto
I have a function that lists and returns dynamodb tables
async def func(connectionId: str | None) -> list[str]:
async with aioboto3.Session().client("dynamodb") as db:
...
0
votes
1
answer
196
views
moto upgrade results in error The queue should either have ContentBasedDeduplication enabled or MessageDeduplicationId provided explicitly
I upgraded moto from 4.1.x to 4.2.x and now I am hitting this error when I run my pytest unit tests.
botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the ...
0
votes
1
answer
318
views
how to mock s3 last_modified for unit tests to a file?
I would like to test the last last_modified timestamp for the s3 file in the unit test. When i try to get the timestamp for an s3 file it always gives me the latest timestamp when i run the unit test, ...
0
votes
1
answer
334
views
Testing AWS emails using Moto - can't get it to work
I'm trying to use moto to test sending aws emails. The documentation is poor, and some things have changed - like @mock_ses doens't appear to exist anymore. Frankly my understanding of mocking is ...
2
votes
1
answer
631
views
Using moto with pandas read_parquet and to_parquet functions
I am trying to write a unit test for a function which uses pd.read_parquet() function and I am struggling to make it work. I have the code below
from moto import mock_aws
import pandas as pd
import ...
26
votes
1
answer
22k
views
ImportError: cannot import name 'mock_s3' from 'moto'
import pytest
from moto import mock_s3
@pytest.fixture(scope='module')
def s3():
with mock_s3():
os.environ['AWS_ACCESS_KEY_ID'] = 'test'
os.environ['AWS_SECRET_ACCESS_KEY'] = '...
0
votes
0
answers
30
views
AWS::SNS::Subscription not created by moto by CloudFormation.create_stack
I have following CloufFormation template
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
ServiceName:
Default: test
Type: String
Resources:
DynamoDBTable:
Properties:
...
-2
votes
1
answer
51
views
Testing Boto3- need to test inactivation of users over 70 days
How can I test my script which deactivates aws users if their last login or access key was last used over 70 days ago. Moto which is mock boto3 does not have the ability to manipulated the "...
-1
votes
1
answer
2k
views
ModuleNotFoundError: No module named 'moto'
Problem
I cannot install the module moto in my Python 3.10.13 environment, even though, it says it's installed. I followed the instructions according to [Github][1], which is to install moto[ec2,s3,...
0
votes
2
answers
525
views
What's wrong with my pytest moto context in this test?
As a frequent user of moto, I'm rather confused about the issue I'm facing.
I set up a test class with a pytest fixture providing a DynamoDB table which I want to access in my test.
Business as usual:
...
0
votes
0
answers
354
views
Moto and boto3 mocks only when specifying the specific python file
I'm using moto to mock my aws calls in my unit tests. When i run pytest tests/test_file.py the unit test will be successful and boto3 gets mocked.
When i run pytest tests/ to detect all the test files ...
0
votes
1
answer
217
views
moto mock_ses list_identities(IdentityType='EmailAddress') returns both email addresses and domains
I'm using mock_ses from moto to mock aws ses functions. I want to test some functions that uses list_identities() but the mocked list_identities() does not behave the same way as the actual function, ...
0
votes
0
answers
308
views
Mock DynamoDB with assumed role using Moto
I am trying to mock a DynamoDB class that uses a session client after assuming a role, and using Moto inside my unit test. The error I keep getting is NoCredentialsError. The DynamoDB class's ...
3
votes
2
answers
7k
views
PanicException: Python API call failed for Cryptography package
I am running Python unit tests in Jenkins with moto for mocking SSM parameters. They worked just fine, until today I did upgrade Python version (3.9.8 -> 3.9.15) and got an error in Jenkins when ...
-1
votes
1
answer
85
views
boto3 failing to upload file in subdirectory of existing bucket
<EDIT> Closing this, as uninstalling and reinstalling moto from scratch fixed the issue. </EDIT>
I am using boto3==1.28.45 with moto==1.3.14 running locally on port 5353.
This has worked ...
4
votes
1
answer
4k
views
How to properly mock functions inside FastAPI endpoint handler
I'm having trouble mocking a function that resides inside a FastAPI endpoint handler. No matter what I've tried it doesn't seem to work. A brief explanation of what I'm trying to test. I have a ...
0
votes
1
answer
1k
views
How to mock correctly a class' aws client with moto?
So I'm doing tests for my lambdas using pytest and moto, the issue is that every lambda has parameters stored in Parameter Store (some also in Secrets Manager) but for the sake of caching I use a ...
1
vote
1
answer
222
views
How to get verification code/change password code in boto3?
I'm writing tests in Moto and Pytest for a confirm sign up route that receives a verification code and a email and uses boto method confirm_sign_up to confirm user.
My question is: After I created a ...
0
votes
0
answers
83
views
moto metadata path has not been implemented
Locally I can run Moto just fine.
When I run moto unit tests from Jenkins, I get the following error:
NotImplementedError: The /latest/dynamic/instance-identity/pkcs7 metadata path has not been ...
0
votes
1
answer
160
views
Deploying SAM template to Moto server?
Is there a way where we can deploy a SAM template to moto server?
We can create resources using the AWS cli and using the --endpoint-url e.g.,
aws iam create-role --endpoint-url=http://127.0.0.1:5000 -...
0
votes
2
answers
3k
views
What is the proper way to use mock_secretsmanager in a module scoped pytest fixture?
This does not work
@pytest.fixture(scope="module")
def monkeypatch_module():
# gross bug: https://github.com/pytest-dev/pytest/issues/363
from _pytest.monkeypatch import MonkeyPatch
...
0
votes
1
answer
2k
views
Unable to mock dynamoDB in pytest fixture
I'm trying to create a dynamoDB in a pytest fixture and use it in other tests to reduce code redundancy, but having some issues.
@pytest.fixture
@mock_dynamodb
def create_test_table(self, mocker):
...
0
votes
1
answer
1k
views
How can I achieve test coverage for `ClientError` exceptions raised in my unit tests for a Python script that utilizes boto3 and moto?
I have this python script snippet with mocked aws infrastructure for a todo list application:
import os
import boto3
import time
import uuid
import json
import functools
from botocore.exceptions ...
1
vote
1
answer
216
views
pytest patch return type of a method call
I want to patch a method return of AWS secrets manager. I am creating a secret and then i am invoking rotate_secret. So once the rotation happens the list_secret call should return a JSON object with ...
0
votes
0
answers
214
views
Passing mock boto3 client in init.py
I am trying to figure out how to pass a mock boto3 client to init.py with pytest, but am having some trouble. When I pass my fixture into the function I'm trying to test, the function called in init....
0
votes
0
answers
229
views
@mock_dynamodb2 saves table context
Im mocking dynamo db client using @mock_dynamodb2 provided by moto.
In my tests Im creating tables and test some input - straight forward.
When I run the code to create the table more than once (even ...
0
votes
1
answer
241
views
Aws Moto redshift statements assertions (Python)
Considering an AWS lambda written in Python that uses boto3 as client to AWS Redshift service.
Considering the following example:
import boto3
import moto
def lambda_handler(event, context):
...
2
votes
2
answers
2k
views
How to access my own fake bucket with S3FileSystem, Pytest and Moto
I'm trying to implement Unit Tests using Pytest, Moto (4.1.6) and s3fs (0.4.2) for my functions that interact with S3.
So far I am able to create a bucket and populate it with all the files that live ...
2
votes
1
answer
666
views
Aws lambda unit test throwing SegmentNotFoundException
I'm trying to write unit tests for an AWS Lambda function that uses the boto3 library to interact with AWS S3. I'm using the moto library to mock S3 in my tests. However, I'm running into an error ...
0
votes
1
answer
408
views
Is there any error with local moto server and cognito-idp in boto3 with awssrp?
I have a local moto server and am verifying cognito-idp in boto3 with awssrp, but I get an error.
The error message is.
Traceback (most recent call last):
File "/tests/get_token.py", line ...
1
vote
1
answer
358
views
NotImplementedError: The analyze_document has not been Implemented
I'm trying to mock textract using moto
I have lambda_function:
from textractcaller.t_call import call_textract, Textract_Features
def lambda_function(event,context)
s3InputDocPath = "s3://...
2
votes
1
answer
2k
views
How to test data from RDS using mock_rds
I am trying to test the data being written to RDS, but I can't seem to be able to mock the DB. The idea is to mock a DB, then run my code and retrieve the data for testing. Could anyone help, please?
...
0
votes
2
answers
2k
views
How to mock Athena query results values with Moto3 for a specific table?
I am using pytest and moto3 to test some code similar to this:
response = athena_client.start_query_execution(
QueryString='SELECT * FROM xyz',
QueryExecutionContext={'Database': myDb},...
0
votes
1
answer
964
views
My function uses my real dynamodb table instead of the moto mocked one
I have a function which get item from a dynamodb table, add 1, put it back in the table and then return the value
import json
import boto3
dynamodb = boto3.resource('dynamodb', 'us-east-1')
table = ...
0
votes
1
answer
612
views
How to know mock postgres host name?
I´m trying to create some unit tests on a python aws lambda proyect using moto.
I´ve created an rds postgres instance using:
@pytest.fixture(scope='function')
def rds(aws_credentials):
with ...
0
votes
1
answer
716
views
How to simulate AWS services and env locally using Python moto?
Is it practically possible to simulate AWS environment locally using Moto and Python?
I want to write a aws gluejob that will fetch record from my local database and will upload to S3 bucket for data ...
4
votes
0
answers
2k
views
How to resolve Pandas Read csv not working for Mock S3?
I created a mock s3 bucket with moto. I put an object into it. I am trying to read with pandas read_csv.
S3_BUCKET_NAME = 'mock_bucket'
def s3_bucket():
mocks3 = mock_s3()
mocks3.start()
...
0
votes
1
answer
67
views
How to mock test ec2 describe_reserved_instance
The describe_reserved_instance function of mock_ec2 has not been implemented in moto lib. In this case, how can one write a unites for the following function in python?
def get_reserved_instance(...
0
votes
0
answers
220
views
Mocking cross account event bridge target rules
Trying to use moto library to mock AWS services. I have been successful trying to put a SQS queue as target to event bridge in the same account Account1. Not sure if moto supports cross account event ...
1
vote
1
answer
808
views
Cannot pytest AWS SES using mock_ses from moto
I am struggling to write mock test for AWS SES.
Below is the content of aws_ses.py the file that I want to test-
def invoke_ses(send_args,ses_client):
try:
response = ses_client....
1
vote
1
answer
1k
views
ExpiredToken error when using python moto lib to mock s3
I am new to Python. Anyone knows how moto mock test work? I am going to test the code which will fetch data from S3 and convert data and upload to S3. I used moto lib to mock s3, however it shows &...