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"?
9 comments
Comment actions Permalink

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

Thank you!

1
Comment actions Permalink

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.

8
Comment actions Permalink

Thank you!  That worked perfectly!

1
Comment actions Permalink

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?

0
Comment actions Permalink

@Claire

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

0
Comment actions Permalink

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.

0
Comment actions Permalink

Hi Mark,

As mentioned above (https://intellij-support.jetbrains.com/hc/en-us/community/posts/205820189/comments/115000136150) 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.

0
Comment actions Permalink

This works for a given type (e.g. Python, Java, etc) of run config, and applies across all projects.  It'd be really useful to also have default environment variables in a project config, that any type of new run config in that project would use/inherit.  Such that I could say "AWS_PROFILE=foo" for my project foo, and any new Java, Bash, Node, whatever run config I create would default to using it.  "inheritance" would probably be better such that I could change it in my project and have any subsequent runs, use that new value

0
Comment actions Permalink

Please feel free to submit a feature request about it to our issue tracker using the link https://youtrack.jetbrains.com/issues/PY

0

Please sign in to leave a comment.