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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.