问题
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?
回答1:
You can prevent the creation of .cache/
by disabling the "cacheprovider" plugin:
py.test -p no:cacheprovider ...
回答2:
You can create an empty file called pytest.ini
in one of the parent directories of your test, are that will become the rootdir
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.
回答3:
Starting from pytest 3.2, you can specify cache_dir
option in pytest.ini
file.
#pytest.ini
cache_dir = .my_cache_dir
If you prefer to use command line argument instead, you can use this switch:
pytest tests -o cache_dir=.my_cache_dir
-o
allows you to specify (and override) pytest.ini specific configuration as command line argument.
回答4:
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_dir
However, 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.
回答5:
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.
来源:https://stackoverflow.com/questions/33310615/is-there-a-way-to-change-the-location-of-pytests-cache-directory