Questions tagged [moto]

Moto is a Python library that allows you to easily mock out tests based on AWS infrastructure and the Boto library (an AWS SDK for python).

Moto is a Python library that allows you to easily mock out tests based on AWS infrastructure and the Boto library (an AWS SDK for python).

Related tags:

Links:

193 questions
25
votes
2 answers

How can I import the boto3 ssm ParameterNotFound exception?

I would like to import the exception that occurs when a boto3 ssm parameter is not found with get_parameter. I'm trying to add some extra ssm functionality to the moto library, but I am stumped at this point. >>> import boto3 >>> ssm =…
zalpha314
  • 1,444
  • 4
  • 19
  • 34
23
votes
3 answers

mock_s3 decorating pytest fixture

I wonder why mock_s3 decorator doesn't work when used as a decorator for pytest fixture. test_with_fixture fails while it provides the same code as the test_without fixture. Well, "the same" as it is decorated explicitly. test_with_fixture raises…
Piotr P
  • 231
  • 1
  • 2
  • 3
13
votes
1 answer

Moto does not work with python unit test setUp() call

I'm working with moto and Python 3.7 to mock some S3 interaction. It appears that moto is working properly if all of the mocking code is contained in the test method. When I move some of the preliminary code to setUp(), the test fails as if…
Paul Waldo
  • 1,131
  • 10
  • 26
13
votes
1 answer

How to mock AWS DynamoDB service?

My service uses AWS DynamoDB as dependency. I want to write unit tests, but I don't know how to mock the DynamoDB service. Could anybody help me with that?
Tiantian
  • 171
  • 1
  • 1
  • 4
11
votes
6 answers

How to mock AWS S3 with aiobotocore

I have a project that uses aiohttp and aiobotocore to work with resources in AWS. I am trying to test class that works with AWS S3 and I am using moto to mock AWS. Mocking works just fine with examples that use synchronous code (example from moto…
Belerafon
  • 488
  • 4
  • 13
9
votes
1 answer

How to test mocked (moto/boto) S3 read/write in PySpark

I am trying to unittest a function that writes data to S3 and then reads the same data from the same S3 location. I am trying to use a moto and boto (2.x) to achieve that [1]. The problem is that the service returns that I am forbidden to access the…
Vassilis Moustakas
  • 573
  • 1
  • 7
  • 17
8
votes
1 answer

moto not mocking ec2?

I'm trying to test some python code that uses boto. I'd rather not try and do an integration test against AWS, so I am trying to mock it out with moto, and it's not behaving as I'd expect. Here's the test code: import io import boto3 from moto…
Geoffrey Wiseman
  • 5,459
  • 3
  • 34
  • 52
7
votes
2 answers

How to mock failed operations with moto, @mock_dynamodb2?

I am currently trying to write unit tests for my python code using Moto & @mock_dynamodb2 . So far it's been working for me to test my "successful operation" test cases. But I'm having trouble getting it to work for my "failure cases". In my test…
CustardBun
  • 3,457
  • 8
  • 39
  • 65
7
votes
0 answers

moto to test aws sts locally

I would like to test my sts setup using moto locally. get_aws_temp_credentials.py import boto3 from botocore.exceptions import ClientError def assume_role(aws_arn=None, aws_session_name=None): if aws_arn is not None and aws_session_name is…
change198
  • 1,647
  • 3
  • 21
  • 60
7
votes
2 answers

how do I test methods using boto3 with moto

I am writing test cases for a quick class to find / fetch keys from s3, using boto3. I have used moto in the past to test boto (not 3) code but am trying to move to boto3 with this project, and running into an issue: class…
user3610360
  • 186
  • 1
  • 1
  • 9
6
votes
1 answer

upload a test file using moto and boto3

I want to test conduct testing on imported files from aws. I mock s3 using moto, in order to not mess with actual data. However, now the aws seems to be empty, thus I decided to upload some test file on mocked s3. How can I do so? This is my…
Aleksandre Bregadze
  • 199
  • 1
  • 3
  • 14
6
votes
1 answer

Moto seems to stop mocking after upgrading boto3

I have upgraded boto3 from boto3==1.7.48 to 1.13.11, and this has broken all of my tests that use Moto. It looks like (worryingly) the mock has stopped working altogether and is trying to actually access s3, here is an example test function that was…
Jamie J
  • 1,168
  • 1
  • 9
  • 22
6
votes
1 answer

How do you add KeyManager to a kms key mocked using moto

I want to create a key that's managed by AWS. So far this is what I have @mock_kms def test_mocking_getting_keys(self): session = boto3.Session(profile_name=profile) client = session.client('kms', 'us-east-2') key = client.create_key( …
Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144
6
votes
3 answers

Moto does not appear to be mocking aws interactions in a pytest

Say I want to mock the following: session = boto3.Session(profile_name=profile) resource = session.resource('iam') iam_users = resource.users.all() policies = resource.policies.filter(Scope='AWS', OnlyAttached=True,…
Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144
6
votes
0 answers

How should I test AWS S3 with moto on Travis?

Moto needs a credentials file, which does not exist on Travis. Travis fails with botocore.exceptions.NoCredentialsError: Unable to locate credentials See example / code. How can I fix this for travis? (Locally, it works) What I tried I added the…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
1
2 3
12 13