default working directory
Answered
I'm running PyCharm 2.6.3
How do I set the default running directory for all Python run configurations?
I've tried going into Run/Debug Configuration->Defaults and setting the Working Directory field for the "Python" template. However, whenever I right click on a script file and choose 'Run' the script is still run with the working directory set to where that script is located. What am I missing?
Thanks
Dmitry
How do I set the default running directory for all Python run configurations?
I've tried going into Run/Debug Configuration->Defaults and setting the Working Directory field for the "Python" template. However, whenever I right click on a script file and choose 'Run' the script is still run with the working directory set to where that script is located. What am I missing?
Thanks
Dmitry
Please sign in to leave a comment.
Same issue here, I need to pass a `-c config-file` option to py.test, but I cannot create sane defaults:
- taking the working directory from defaults would solve my problem, but this is not the case as stated above
- I could not find a way to interpolate the "project root dir" variable in the "Additional arguments" field, otherwise I could have used something like `-c ${projectRoot}/config-file`. Also, I don't want to create a custom path variable as it won't work out of the box for my colleagues).
Until one of these two issues is fixed, for each new test that I want to run, I need to:
- run the test
- wait for it to fail because the configuration is wrong
- edit the configuration manually
- re-run the test
Not a great workflow, unfortunately...
Hi Romainchossart! I believe one can set default working directory for tests in default run configurations:
Make sure you are using the latest stable version. Has it helped in your case?
On my build (2017.1.2), setting this value has no effect when running a new test from the editor: the working directory is always set to the test file directory.
Yeap, this behaviour was recently fixed, would you mind trying 2017.1.4 or (2017.2 EAP)?
Ha, I confirm the behaviour is fixed on 2017.1.4, thanks! <3
I have this kind of structure for projects:
project-name
- src
- tests
So root dir is project-name and all tests and source code should run with project-name as root directory. I change Templates setting, mark directory as source. But anyway, I still correct working directory manually every time when I run new test.
PS after restart it began to work. Anyway. Is it marked in documentation how to setup run/tests config root directory? Firstly I looked at the dock, marking directory as source etc etc etc. And now figure it out. Looks like it is not very clear in documentation.
This works as a project-wide setting. How can this be set so that all default run configurations (across all projects) use the root path of the respective project?
Hi Fabio,
Maybe I have misunderstood, but have you tried https://www.jetbrains.com/help/pycharm/changing-default-run-debug-configurations.html?
Hi Sergey,
thanks for checking back.
As I said, this works fine on a per-project basis.
The issue is that I have to do this for every new project (and for run as well as test configurations) again every time.
I would like a default for all run configurations across all projects.
E.g. a global setting could have the value $PROJECT_ROOT so that all run configurations have the working directory default to their respective project root
Is it clearer now?
Thank you for the update.
Ah, I see.
No, unfortunately this isn't possible at the moment. See https://youtrack.jetbrains.com/issue/IDEA-65915 and https://youtrack.jetbrains.com/issue/IDEA-137080. Please vote for them and follow for future updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.
Ok, thanks for the fast responses and the links. Will do.
Just a note that this solution also works for Jest with Angular multi-project workspaces. I'm using @angular-builders/jest and when I attempted to run a test directly from the editor I was getting and error like "Module <rootDir>/jest-setup.js in the setupFiles option was not found." Setting the default project folder in the Jest configuration: