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

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

What you want to insert there is called a macro, which is a context-dependent variable: $FileName$ (current file in this case). Unfortunately this doesn't work yet in Run configurations.

Workaround - use External Tools

  1. Settings > Tools > External Tools
  2. [+]
  3. set "Program" as path to your script/program ('py.test')
  4. in "Arguments" use button [Insert Macro...] on the right. There will be a list of possibilities. For example you wanted $FileName$ for the current file.

If you want both of those commands in one External Tool command, then create a bash script:

#!/bin/bash -exu

py.test -m mymarker $@
autopep8 $@

Finally you can use it via [Tools]>[External Tools], [Right click on a file]>[External Tools] or you can add a shortcut to the command.