moto: Unable to Mock Profiles

This is a duplicate of the following issue seems to have been closed without a fix: https://github.com/spulec/moto/issues/889

My tests are failing because it requires the profiles to actually exist within ~/.aws/config. Given that this is a mocking library, we should be able to mock this functionality. Otherwise I am going to have to overwrite /.aws/config files anywhere that the tests are run for this to work.

Example error:

 botocore.exceptions.ProfileNotFound: The config profile (myenv) could not be found

Example code

@mock_ssm
def test_whatever():
    env = boto3.session.Session(profile_name="myenv")
    ssm = env.client('ssm')
    ...

This can be fixed on my machine by adding the valid profiles, but I need these tests to be portable so that is not an option, ideally this should be mockable.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 18

Most upvoted comments

Here is a workaround I found for anyone who is still having issues with this: https://stackoverflow.com/questions/59535311/moto-does-not-appear-to-be-mocking-aws-interactions-in-a-pytest/65017491#65017491

Basically you need to create an AWS_SHARED_CREDENTIALS_FILE env var that points to a fake aws creds file in your test suite