Secure Environment Variables not available in Python Build if using Tox

So I’m experiencing a weird issue that has me stumped.

I have an opensource library (see here) that wraps a third-party’s RESTful API. I’m running a series of tests in Python 3.7 on the xenial distribution, and the tests rely on an environment variable to authenticate against the third-party’s API. Tests pass locally using the configured environment variable. No problems.

In Travis CI, I have attempted two different things per TravisCI’s documentation:

  1. I have configured the environment variable using the Travis CI web-based UI, setting it to be available in all branches (TEST_API_KEY and WALKSCORE_TEST_API_KEY).

  2. I have configured an encrypted form of the environment variable within my .travis.yml file (WALKSCORE_TEST_API_KEY).

When I view my job logs, it is clear that there are environment variable export statements for my secure/encrypted environment variables. Should be available to my code, right?

Alas, my code is unable to access the exported environment variables. For debug purposes, I even included a print statement in my tests to show me all of the environment variables available in my Python environment and no luck! The log shows all of the environment variables exported in the build environment, but for whatever reason these variables are not accessible to my Python code.

Here is a link to an example job build that shows the problem and also lists all of the environment variables accessible via Python:

Does anyone have any suggestions? I’m sure I’ve got something misconfigured somewhere, but my understanding is that configured environment variables should be available in the Python execution environment within my job.

tox is the culprit. It removes envvars arbitrarily from test Python processes. See

for another case where this practice causes problems. See that topic for a workaround and raise the issue with Tox developers if you want it changed.

Perfect - thank you! That link / workaround worked to resolve the issue. Thanks for the help!