Is there a way to change the location of pytest's .cache directory?

旧巷老猫 提交于 2019-11-30 11:12:30

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

py.test -p no:cacheprovider ...

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.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!