30

I'm using Pycharm for this years Advent of Code and I'm using pytest for testing all of the examples and output.

I'd prefer it if pytest didn't create the .cache directories throughout my directory tree. Is there anyway to disable the creation of .cache directories when tests fail?

Endzeit
  • 4,810
  • 5
  • 29
  • 52
labarna
  • 668
  • 1
  • 9
  • 16

1 Answers1

47

There are two basic options:

  • disable the caching altogether (the caching is done with the cacheprovider plugin):

    pytest -p no:cacheprovider
    

    -p is used to disable plugins.

  • changing the cache location by tweaking the cache-dir configuration option (requires pytest 3.2+)

    Sets a directory where stores content of cache plugin. Default directory is .cache which is created in rootdir. Directory may be relative or absolute path. If setting relative path, then directory is created relative to rootdir.

Here is a sample PyCharm run configuration with the no:cacheprovider:

enter image description here

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thanks, that's super useful. Do you know if there's a way to change PyCharm's behavior to run it's tests with `-p no:cacheprovider`? – labarna Dec 19 '17 at 22:27
  • 2
    @labarna sure, you can add additional command-line arguments in your `py.test` run configuration. Let me know if you want a sample configuration screenshot. Thanks. – alecxe Dec 19 '17 at 22:29
  • 1
    @labarna sure, added a sample run configuration screenshot, please let me know if it helps. – alecxe Dec 20 '17 at 14:33
  • 1
    Worth noting, in the "Run/Debug Config" dialog you can click "Edit configuration templates.." to add the argument to all new pytest run configurations. That way when you right click to run a specific test it will already have the right config. – Ryan Widmaier May 23 '22 at 14:20
  • 2
    pytest.ini configuration files in the project can use `addopts = -p no:cacheprovider` so you don't need to set it the Pycharm Run Configurations as well, so that'll help with command-line runs as well. – bdfariello Sep 13 '22 at 13:23