'If you want your unit-tests to run against different databases in different environments, how do you specify the database?

I have two db's, one already is running against unit-tests in both jenkins and locally. What I want to do is when we are in Jenkins env then just run the unit-tests against the standard db (this happens already), but if we are in local I want it to connect to another db called local-test-db. I am already able to check if we are in the Jenkins env by asking if 'JENKINS_URL' in os.environ if so then do nothing and have it run against public db, otherwise, we are in local, in which case I want it to connect to the local-test-db.

How is this done?

If we have some check in the beginning of the code like so:

if 'JENKINS_URL' not in os.environ:

# somehow connect to the local-db

I can see both of the db's in mysql just not sure how to specify them in this condition.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source