我需要能够将pytest的.cache目录的位置更改为env变量WORKSPACE。由于服务器权限超出我的控制范围,我遇到此错误,因为我的用户没有权限在运行测试的目录中写入:
py.error.EACCES: [Permission denied]: open('/path/to/restricted/directory/tests/.cache/v/cache/lastfailed', 'w')
有没有办法将.cache目录的路径设置为环境变量WORKSPACE?
您可以通过禁用“cacheprovider”插件来阻止创建.cache/
:
py.test -p no:cacheprovider ...
您可以在测试的一个父目录中创建一个名为pytest.ini
的空文件,这将成为将在其中创建rootdir
的.cache
。
见https://pytest.org/latest/customize.html
它不是理想的,但它允许某种形式的定制。
从PyTest 3.2开始,应该有一个命令行选项来设置.cache
目录的位置:https://docs.pytest.org/en/latest/customize.html#confval-cache_dir
但是,使用PyTest 3.2.5,这对我来说失败了unrecognized option: --cache_dir
错误。如果有人能够使这个工作,请说出来。
没有明确的选项来更改命令行上的缓存目录,但可以使用-o
选项覆盖pytest.ini中的选项:
pytest -o cache_dir=$WORKSPACE ...
有关pytest --help
选项的更多信息,请参阅-o
的输出。
另外,作为参考,我使用的是pytest 3.7.1。