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?

Jay
  • 71
  • 1
  • 8
  • Can you please explain more from where and how you set `os.environ['SNS_TOPIC']`? During test run or from anywhere else? – Chanda Korat Sep 26 '17 at 08:12

1 Answers1

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.

Jay
  • 71
  • 1
  • 8