I need to be able to change the location of pytest's .cache directory to the env variable, WORKSPACE. Due to server permissions out of my control, I am running into this error because my user does not have permission to write in the directory where the tests are being run from:
py.error.EACCES: [Permission denied]: open('/path/to/restricted/directory/tests/.cache/v/cache/lastfailed', 'w')
Is there a way to set the path of the .cache directory to the environment variable WORKSPACE?
You can create an empty file called
pytest.ini
in one of the parent directories of your test, are that will become therootdir
in which the.cache
will be created.See https://pytest.org/latest/customize.html
It's not ideal but it allows some form of customization.
Since PyTest 3.2, there is supposed to be a command-line option for setting the location of the
.cache
directory: https://docs.pytest.org/en/latest/customize.html#confval-cache_dirHowever, using PyTest 3.2.5, this fails for me with an
unrecognized option: --cache_dir
error. If anybody is able to get this working, please speak up.There is no explicit option to change the cache directory on the command line, but it is possible to override the options in pytest.ini with the
-o
option instead:pytest -o cache_dir=$WORKSPACE ...
See the output of
pytest --help
for more info about the-o
option.Also, for reference I'm using pytest 3.7.1.
You can prevent the creation of
.cache/
by disabling the "cacheprovider" plugin: