Is there a way to change the location of pytest's .cache directory?
pytest ignore directory
pytest mark usefixtures
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?
You can prevent the creation of
.cache/ by disabling the "cacheprovider" plugin:
py.test -p no:cacheprovider ...
Configuration, passing the --ignore=path option on the cli. pytest allows multiple --ignore options. subversion or sphinx-build directories or into any tmp prefixed directory. Initialization: determining rootdir and inifile¶. pytest determines a rootdir for each test run which depends on the command line arguments (specified test files, paths) and on the existence of ini-files. The determined rootdir and ini-file are printed as part of the pytest header during startup.
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.
It's not ideal but it allows some form of customization.
Changing standard (Python) test discovery, to modify sys.path / PYTHONPATH or influence how modules are imported. If one is matched, it becomes the ini-file and its directory becomes the rootdir. This section assumes some familiarity with the Django test runner, Django database creation and pytest fixtures. Fixtures ¶ There are some fixtures which will let you change the way the database is configured in your own project.
Starting from pytest 3.2, you can specify
cache_dir option in
#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.
basic test configuration, test run, the current working directory is used to start the search. How to change command line options defaults¶. It can be tedious to type the same series of pytest_runtest_logstart (nodeid, location) [source] ¶ signal the start of running a single test item. This hook will be called before pytest_runtest_setup() , pytest_runtest_call() and pytest_runtest_teardown() hooks.
Since PyTest 3.2, there is supposed to be a command-line option for setting the location of the
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.
pytest import mechanisms and sys.path/PYTHONPATH, Here's a list of scenarios where pytest may need to change sys.path in order to import pytest will find foo/bar/tests/test_foo.py and realize it is part of a package pytest for enterprise¶. Available as part of the Tidelift Subscription. The maintainers of pytest and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications.
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
Also, for reference I'm using pytest 3.7.1.
Basic test configuration, If one is matched, it becomes the ini-file and its directory becomes the rootdir. all the way down to the root # now look for setup.py path/setup.py setup.py . Set the directory basename patterns to avoid when recursing for test discovery. b. Left click Personalize, Display settings. c. In the Monitor window that opens you should see your two monitors. Find out which is which by clicking Identify Monitors. d. Click and drag the right hand monitor left to the left of the original left monitor and release the drag. That should change the positions of the two monitors so that the
Good Integration Practices, This is similar to running python setup.py develop or conda develop in that it For examples of how to customize your test discovery Changing standard Putting tests into an extra directory outside your actual application code might be useful Changing your app before Django gets set up¶. pytest-django calls django.setup() automatically. If you want to do anything before this, you have to create a pytest plugin and use the pytest_load_initial_conftests() hook, with tryfirst=True, so that it gets run before the hook in pytest-django itself:
Changing standard (Python) test discovery, test directories and modules during collection by passing the --ignore=path option subversion or sphinx-build directories or into any tmp prefixed directory. It would be nice to change pytest-bdd so that it doesn't need to modify the line numbers to avoid more problems like this.
How to change the default rootdir ($PWD) to some other path · Issue , I am using pytest for testing a C project (not Python), so it is quite How to change the default rootdir ($PWD) to some other path #4594. There are two ways in which this issue can be solved. With the help of classic xunit style setup along with teardown methods. By using fixtures (recommended). xunit style of fixtures is already supported in unittest but pytest has a much better way of dealing with fixtures.