summaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-10-07 13:52:16 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-10-08 09:39:19 +0000
commit7f00500184d799539980ad5fc4d5ef5ddde16d35 (patch)
treee31d0addd07b9f83510692f313bf344bd009f719 /tests/conftest.py
parentd913e5cbf8035fac76b90cde3cac71b08ec70a13 (diff)
downloadbuildstream-7f00500184d799539980ad5fc4d5ef5ddde16d35.tar.gz
setup.cfg: Fix xdg env vars to not affect the hostbschubert/fix-xdg-temppaths
A fix was made in https://gitlab.com/BuildStream/buildstream/merge_requests/1244 in order to set xdg_* env variables inside of the test's directory to avoid importing data from the host. There was however still two problems: - When a variable was not set, it was set with a relative path, which would create a configuration for BuildStream that is invalid. - When a variable was set and running with pytest directly, we would still use the variable's value, which would be the host one. This ensure this can never happen, by not relying on the same variable's name and always overriding them.
Diffstat (limited to 'tests/conftest.py')
-rwxr-xr-xtests/conftest.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 9189d263e..68fdba7fb 100755
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -137,3 +137,21 @@ register_repo_kind('zip', Zip, None)
# buildstream.testing
def pytest_sessionstart(session):
sourcetests_collection_hook(session)
+
+
+#################################################
+# Isolated environment #
+#################################################
+@pytest.fixture(scope="session", autouse=True)
+def set_xdg_paths(pytestconfig):
+ for env_var, default in [
+ ("HOME", "tmp"),
+ ("XDG_CACHE_HOME", "tmp/cache"),
+ ("XDG_CONFIG_HOME", "tmp/config"),
+ ("XDG_DATA_HOME", "tmp/share"),
+ ]:
+ value = os.environ.get("BST_TEST_{}".format(env_var))
+ if value is None:
+ value = os.path.join(pytestconfig.getoption("basetemp"), default)
+
+ os.environ[env_var] = value