How to set "default" environment variables?

I have a few environment variables set in my "run configuration", but when I right-click a single test and click in "Run test" the new "run configuration" is created with empty environment variables, making my test fail.

Is there a way to set some default environment variables that will be automatically set in every new "run configuration"?

I have the same question.  This is very frustrating.  How can I set some default variables for each test to "inherit"?

Thank you!


Please, go to `Run| Edit Configurations| Defaults| Python tests| Unitests/Nosetests/...` and specify your environment variables in "Environment variables" field, then apply changes. After that all newly created run configurations for tests will follow this setting.


Thank you!  That worked perfectly!


I tried using this with IntelliJ  2017.2 with a node config and also with an npm config but I don't see any Env tab. Please help?



It's not a tab, there is a field "Environment variables" (for npm there is "Environment" field).


Sorry, I'm having a similar problem in Pycharm-2018.3. I selected "Run|Edit Configurations" but there is no "Defaults" button, tab or field to select. I could add a variable using the "Environment Variables" field in that screen, but I don't want to do that for each of the tests in the module. I'd like to be able to set the variable once for the module,  and have all tests in that module use that variable. I tried setting the variable in a configuration for the module itself, but running individual tests in that module did not inherit it.


Hi Mark,

As mentioned above ( you can do that for a template of needed run configuration. Thus, all new run configurations will have these environment variables. As about existing run configurations - you should update them all manually.


Please sign in to leave a comment.