2016-10-13 22:46:43 +00:00
|
|
|
import os
|
2016-11-13 10:19:58 +00:00
|
|
|
import os.path
|
2016-10-14 02:42:13 +00:00
|
|
|
import sys
|
2016-10-13 22:46:43 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2016-12-13 18:27:01 +00:00
|
|
|
# needed to get pretty assertion failures in unit tests:
|
2016-12-15 02:02:06 +00:00
|
|
|
pytest.register_assert_rewrite('borg.testsuite')
|
2016-10-13 22:46:43 +00:00
|
|
|
|
2016-10-14 02:42:13 +00:00
|
|
|
# This is a hack to fix path problems because "borg" (the package) is in the source root.
|
|
|
|
# When importing the conftest an "import borg" can incorrectly import the borg from the
|
|
|
|
# source root instead of the one installed in the environment.
|
|
|
|
# The workaround is to remove entries pointing there from the path and check whether "borg"
|
|
|
|
# is still importable. If it is not, then it has not been installed in the environment
|
|
|
|
# and the entries are put back.
|
|
|
|
|
|
|
|
original_path = list(sys.path)
|
|
|
|
for entry in original_path:
|
2016-11-13 10:19:58 +00:00
|
|
|
if entry == '' or entry == os.path.dirname(__file__):
|
2016-10-14 02:42:13 +00:00
|
|
|
sys.path.remove(entry)
|
|
|
|
|
|
|
|
try:
|
|
|
|
import borg
|
|
|
|
except ImportError:
|
|
|
|
sys.path = original_path
|
|
|
|
|
|
|
|
|
2016-10-13 22:46:43 +00:00
|
|
|
@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)
|