Search code examples
pycharmpytestjetbrains-ide

Applying a custom PyTest run configuration to all child tests in directory?


I have some tests I'm running with PyTest and Selenium, and would like to be able to run individual tests with the run button in the gutter. I was following this guide to create a custom run configuration from the parent directory of all tests:

https://www.jetbrains.com/help/pycharm/run-debug-configuration-py-test.html

This works for running every test in the directory, but running any of the individual child tests generates a new run configuration without the required settings.

Is there a way to automatically generate a run configuration with specific settings (working directory, environment variables, and additional parameters in particular) for each test?


Solution

  • As far as I'm aware your only option is to edit the defaults (template) used by all Run/Debug Configurations when such a config gets created. See the official help page: https://www.jetbrains.com/help/pycharm/run-debug-configuration.html#change-template

    enter image description here

    NOTES:

    • There is only 1 defaults/template per each run/debug config type.
    • Therefore you cannot have one set of settings for this folder and another for some other one. All new configs will use the same template. You can still modify them later of course.
    • Editing the template affects only the current project/window (since it's a project-specific entity). Project opened in another frame/window has its own defaults/templates.
    • Editing the template does not affect already existing configurations.