diff options
author | Thomas Waldmann <tw@waldmann-edv.de> | 2016-10-13 23:59:28 +0200 |
---|---|---|
committer | Thomas Waldmann <tw@waldmann-edv.de> | 2016-10-13 23:59:28 +0200 |
commit | 4e4847ccceacb64191f3cf7a31159f9ce993767d (patch) | |
tree | 18b54eb93162afbc8dcf0158ac7375c118a63dde /conftest.py | |
parent | a2dfe68609f6f7c2af4511880f83e5182727d822 (diff) |
point XDG_*_HOME to temp dirs for tests, fixes #1714
otherwise it spoils the user's nonces and cache dirs with lots of files.
also: remove all BORG_* env vars from the outer environment
Diffstat (limited to 'conftest.py')
-rw-r--r-- | conftest.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/conftest.py b/conftest.py index 5caf8a09a..312f57a20 100644 --- a/conftest.py +++ b/conftest.py @@ -1,5 +1,7 @@ import os +import pytest + from borg.logger import setup_logging # Ensure that the loggers exist for all tests @@ -16,6 +18,17 @@ def pytest_configure(config): constants.PBKDF2_ITERATIONS = 1 +@pytest.fixture(autouse=True) +def clean_env(tmpdir_factory, monkeypatch): + # avoid that we access / modify the user's normal .config / .cache directory: + monkeypatch.setenv('XDG_CONFIG_HOME', tmpdir_factory.mktemp('xdg-config-home')) + monkeypatch.setenv('XDG_CACHE_HOME', tmpdir_factory.mktemp('xdg-cache-home')) + # also avoid to use anything from the outside environment: + keys = [key for key in os.environ if key.startswith('BORG_')] + for key in keys: + monkeypatch.delenv(key, raising=False) + + def pytest_report_header(config, startdir): tests = { "BSD flags": has_lchflags, |