Reputation: 5078
I have a nose test that uses a pathname to a png file in the tests directory. One path works in local testing, one path works on Travis. How do I check when the code is run on Travis?
Edit: Here is the actual code.
Upvotes: 12
Views: 1483
Reputation: 19200
In hindsight, all the answers above were correct. However, I would also like to document another cause that wasted me hours of my life.
If you happen to be maintaining a code base which uses the popular tox to orchestrate your tests, you might not know this tox behavior:
By default tox will only pass the PATH environment variable (and on windows SYSTEMROOT and PATHEXT) from the tox invocation to the test environments. If you want to pass down additional environment variables you can use the passenv option:
[testenv]
passenv = TRAVIS
Upvotes: 1
Reputation: 4465
You could check for the existence (or value) of an environment variable. It looks like Travis defines several by default (see here).
For example:
import os
istravis = os.environ.get('TRAVIS') == 'true'
Upvotes: 6
Reputation: 22942
To check the existence of TRAVIS:
import os
is_travis = 'TRAVIS' in os.environ
Upvotes: 18