Search code examples
intellij-ideapycharm

How to use current file as parameter to Run configuration in pycharm


I want to create custom run configurations, but i cannot figure out how to get the current file name as a parameter...

I would like to do something like this:

py.test -m mymarker %f

autopep8 %f

where %f is the current file name.


Solution

  • The answer by Ctrl+C already hints at $FileName$ and at least in the current version 2020.2 of PyCharm this works in Run Configurations.

    1. Create a run configuration as you desire, e.g. Python
    2. In Parameters field you can simply use macros like $FileName$ or $FilePath$. Or click on the + at the right end for a full list
    3. Hit the Run button or Shift+F10 by default while your target file is opened