-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test cases written in moto using Latest version of boto3 fails #1793
Comments
Similar problem with |
pin botocore and boto3 in tests getmoto/moto#1793
It looks like the issue is actually with botocore >= 1.11.0 which no longer uses requests and instead directly uses urllib3: boto/botocore#1495. This means moto probably can't use responses anymore... |
As described in getmoto/moto#1793, moto doesn't seem to be properly mocking S3 calls with boto3 1.8 releases, so this PR pins the version of boto3 in test-requirements.txt to the latest 1.7 boto3 release Also: this PR removes the `awscli` dependency, which transitively depends on a botocore version (1.11) that causes the s3 artifact store tests to fail.
Obviously we want to update moto so that it can work with the new implementation of botocore. Whilst we figure out what this looks like, is it worthwhile restricting moto's EDIT: I have added a PR for this as a discussion starter |
botocore v1.11.0 changed it's internal implementation so that it now uses a different library for HTTP requests. This means that moto's mocking will not work, and test code will inadvertently call the live AWS service. As an interim solution to reduce the impact of this breakage, we restrict the "required" (ie. recommended) version of botocore so that users will be less likely to use an incompatible version, and will receive a pip warning when they do.
Boto3 1.8 breaks our tests using moto. See getmoto/moto#1793 . We can unpin when moto is updated.
Boto3 1.8 breaks our tests using moto. See getmoto/moto#1793 . We can unpin when moto is updated. This also has to add boto-core as a requirement to allow moto to install.
pinning to boto3<1.8 is not really a solution as it would outdate the library pretty soon and doesn't solve when installing dependencies relying on newer versions either, as this will cause incompatibilities. |
@grudelsud I agree that pinning boto3 is not a viable long-term solution, and introduces problems of its own. But given that users are currently being affected by tests silently falling back to making real boto3 calls (which can have significant unexpected side-effects if you happen to have valid AWS credentials available), it seems worthwhile to consider a quick solution as well a permanent solution. I feel that, for now, the problems from pinning boto3 are lower severity than doing nothing. That said, I would be a million times happier if someone put forward a genuine fix. But I lack the time and knowledge to do that myself at this point, or even to guess how much work would be involved. |
getmoto/moto#1793 Until we either move entirely off moto to botocore.Stubber, this is the easiest workaround.
getmoto/moto#1793 Until we either move entirely off moto to botocore.Stubber, this is the easiest workaround.
@garyd203 I've been driving a lot of the changes to get |
Hi @joguSD , thanks for asking. I'm just an occasional contributor to The goal of Moving forward, there seem to be a few choices for how we could do this better. I suspect we are constrained to work with the HTTP request rather than some other part of the
Do you have any opinion on these (or other) implementation choices, from Again, don't take any of this discussion as definitive (I can't speak for the |
Finally! |
I would say, that people shouldn't be afraid to run unit tests that use moto risking their real AWS envs being modified. I don't suspect that there are some folks that would like to run tests that use both real AWS and still mock some bits of AWS. |
I can still reproduce the issue with S3 and SQS tests on |
@yitzikc Are your mocks running before your code is executed? |
I just added a Protip to my post above, which should assist users when designing their tests with moto. |
I got the same problem and my solution was to import the moto librairies before the boto3 librairie. |
Indeed when care is taken to import Moto before any imports of Boto3 or Botocore, the mocking works properly. I had to watch for imported modules which were importing Boto. Also, when running Pytest on multiple files, imports for tests in one file would interfere with the ones run subsequently. I had to import Moto in any test files that might import modules which ultimately import Boto. |
I just made a PR to introduce more AWS Config features (#2363), and I updated the readme with the wording in my post above. Please review and let me know if there is anything else I should add: |
Changing import order still not working to me 😢 . Using same version as boto3 = "==1.9.189" botocore = "==1.12.189" moto = "==1.3.13" / "==1.3.10" |
The problem is not the import order -- it's the order upon which a boto client is instantiated. If it is instantiated BEFORE a mock is established, it won't work. Please review: https://github.com/spulec/moto#very-important----recommended-usage |
Hi guys, not sure if I understand everything correctly, but I allowed myself to report an issue to boto3 to make mocking easier - can anyone from moto core team comment on boto/boto3#2123 - maybe there's something boto team could do to avoid such problems? This bug is not the only one reported to moto - some of those issues are more than 1 year old and people still have problems that tests hit AWS servers. |
I'm actually curious if I permanently fixed this issue #2578 |
- Fixes getmoto#2575 - Also upgraded Travis CI to make use of Bionic instead of Xenial - This may also address concerns raised in getmoto#1793
Can you all verify if the latest |
- Fixes getmoto#2575 - Also upgraded Travis CI to make use of Bionic instead of Xenial - This may also address concerns raised in getmoto#1793
@mikegrima, Thank you very much for your responses.
This is my source code file named
here is my test file
Anything i'm missing here. Appreciate your help. |
I used decorator around
The above invalid security token went off.
Any idea how to mock this line Can we mock |
Hi @karthikvadla, where in your test are you calling the 'DescribeTable' operation, i.e. on which line is it failing? I can't see it in the code you provided The creation time can be accessed like this:
|
Hi all im getting the same issue reported above. any advice would be greatly appreciated: from moto import mock_s3
import boto3
import pytest
import os
@pytest.fixture(scope='function')
def aws_credentials():
"""Mocked AWS Credentials for moto."""
os.environ['AWS_ACCESS_KEY_ID'] = 'testing'
os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing'
os.environ['AWS_SECURITY_TOKEN'] = 'testing'
os.environ['AWS_SESSION_TOKEN'] = 'testing'
@pytest.fixture(scope='function')
def s3(aws_credentials):
with mock_s3():
yield boto3.client('s3', region_name='us-east-1')
def test_create_bucket(s3):
# s3 is a fixture defined above that yields a boto3 s3 client.
# Feel free to instantiate another boto3 S3 client -- Keep note of the region though.
s3.create_bucket(Bucket="somebucket")
result = s3.list_buckets()
assert len(result['Buckets']) == 1
assert result['Buckets'][0]['Name'] == 'somebucket'
output:
versions:
|
@drewmullen The name of your test file conflicts with the moto package. Rename your file to something other than |
Edit: I think I just need to be more careful with import order Is this meant to be fixed? I'm seeing what looks to be a similar issue trying to mock out DynamoDB calls. moto==1.3.14 Partial example: def setup_table():
ddb_client = boto3.client('dynamodb')
ddb_client.create_table(
AttributeDefinitions=[
{'AttributeName': 'email', 'AttributeType': 'S'},
{'AttributeName': 'timestamp', 'AttributeType': 'S'},
],
TableName='contact-form-submissions',
KeySchema=[
{'AttributeName': 'email', 'KeyType': 'HASH'},
{'AttributeName': 'timestamp', 'KeyType': 'RANGE'},
],
ProvisionedThroughput={'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1},
)
@mock_dynamodb2
def test_save_to_db():
setup_table()
result = save_to_db(DATA)
assert result is True I'm getting an error:
And it looks like that table is getting created on real AWS, not mocked as I'd expected. Am I doing something wrong or is there a regression? |
This is happening for me with moto 1.3.16 - botocore.exceptions.ClientError: An error occurred (InvalidClientTokenId) when calling the Publish operation: No account found for the given parameters rolling back and using 1.13.10 seems the resolve the issue |
Hi @mickog, this might fix your issue: |
Cheers @bblommers will take a look at refactoring my tests, |
The link from @bblommers in the comment above is now contained in the documentation here : https://docs.getmoto.org/en/latest/docs/getting_started.html#recommended-usage |
Test cases written in moto makes actual AWS API calls to botocore instead of mocking them. This happens with the latest version of boto3 (1.8.). It used to work fine without issues with 1.7. versions.
Sample code to reproduce error
Expected result
Method should return the
ListBuckets
response. It should look something like:Actual error
Full stack trace
Library versions
The text was updated successfully, but these errors were encountered: