有没有办法改变pytest的.cache目录的位置?

问题描述 投票:18回答:4

我需要能够将pytest的.cache目录的位置更改为env变量WORKSPACE。由于服务器权限超出我的控制范围,我遇到此错误,因为我的用户没有权限在运行测试的目录中写入:

py.error.EACCES: [Permission denied]: open('/path/to/restricted/directory/tests/.cache/v/cache/lastfailed', 'w')

有没有办法将.cache目录的路径设置为环境变量WORKSPACE?

python caching directory pytest
4个回答
23
投票

您可以通过禁用“cacheprovider”插件来阻止创建.cache/

py.test -p no:cacheprovider ...

7
投票

您可以在测试的一个父目录中创建一个名为pytest.ini的空文件,这将成为将在其中创建rootdir.cache

https://pytest.org/latest/customize.html

它不是理想的,但它允许某种形式的定制。


1
投票

从PyTest 3.2开始,应该有一个命令行选项来设置.cache目录的位置:https://docs.pytest.org/en/latest/customize.html#confval-cache_dir

但是,使用PyTest 3.2.5,这对我来说失败了unrecognized option: --cache_dir错误。如果有人能够使这个工作,请说出来。


0
投票

没有明确的选项来更改命令行上的缓存目录,但可以使用-o选项覆盖pytest.ini中的选项:

pytest -o cache_dir=$WORKSPACE ...

有关pytest --help选项的更多信息,请参阅-o的输出。

另外,作为参考,我使用的是pytest 3.7.1。

© www.soinside.com 2019 - 2024. All rights reserved.