0

I am using pytest to run tests for my python services that run in AWS.

I am trying to test a service which triggers from an SNS topic. So my test writes to the SNS topic. The topic ARN is different for dev, staging, prod.

In the test I would like to be able to access the topic ARN using the same environment variable and pick up the right topic for each environment.

self.sns_topic_arn = os.environ['SNS_TOPIC']

I have a service which does set, build, test which is independent of all my services and deployment environments.

I refer to this discussion on how to pass the env vars How to pass environment variables to pytest

However I am not able to figure out how to set the value per environment. Is there a template or a best practice?

1
  • Can you please explain more from where and how you set os.environ['SNS_TOPIC']? During test run or from anywhere else? Commented Sep 26, 2017 at 8:12

1 Answer 1

1

I am posting the solution which works for us. I am not sure this would be a useful answer in all use cases or that my question applies to many users. The way our test & deployment is set up, this turned out to be simple. I didn't figure it out right away to start with :|.

I have a service which does set, build, test which is independent of all my services and deployment environments.

The service runs these tests in a docker container. The tests are run as acceptance tests using AWS code pipeline and there's a Docker config for each environment. So we are able to set the right 'SNS_TOPIC' as the environment variable in each config.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.