Is there a way to change the location of pytest

2019-02-11 16:39发布

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?

4条回答
Viruses.
2楼-- · 2019-02-11 17:15

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.

查看更多
smile是对你的礼貌
3楼-- · 2019-02-11 17:15

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.

查看更多
看我几分像从前
4楼-- · 2019-02-11 17:32

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.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-02-11 17:33

You can prevent the creation of .cache/ by disabling the "cacheprovider" plugin:

py.test -p no:cacheprovider ...
查看更多
登录 后发表回答