How to run python tests in PyCharm/IntelliJ

I have mine set up so that I can run python tests by right-clicking. I do have to compile from the command line first, though – it’s possible to add a gradle task to be done before the python test, but that wastes many seconds.

  1. Ensure that your Python interpreter is set up correctly. cmd ; > modules can bring up the module menu.
  2. From the top menu, go to Run > Edit Configurations
  3. From the left menu, navitage to Defaults > Python tests > Unittests
  4. edit your default to look like this, and hit save:

The environment variable hidden for me is


We need this to add py4j and pyspark to the python path.

Update: I no longer use the former method. I now have the following lines in my ~/.profile (important that it is this dotfile in particular, intelliJ will not look at shell-specific dot files):

export HAIL_HOME=/Users/tpoterba/hail/hail
export PYSPARK_SUBMIT_ARGS="--conf spark.driver.extraClassPath=$JAR_PATH --conf spark.executor.extraClassPath=$JAR_PATH --driver-memory 8G pyspark-shell"

Then I use the following configuration:

This will require a reboot of intellij and possibly the OS.