test: ignore the real XDG_CONFIG_HOME during tests
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 27 Jul 2020 01:26:51 +0000 (11:26 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 27 Jul 2020 09:26:46 +0000 (19:26 +1000)
Let's not have our tests fail if the user has an incompatible
$XDG_CONFIG_HOME/xkb directory.

libxkbcommon has fallbacks when XDG_CONFIG_HOME isn't set so we need to override
this with a real directory instead of just unsetting it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/tool-option-parsing.py

index df4ff77..c503176 100755 (executable)
@@ -27,6 +27,7 @@ import resource
 import sys
 import subprocess
 import logging
+import tempfile
 
 try:
     import pytest
@@ -300,4 +301,10 @@ def test_interactive_wayland(xkbcli_interactive_wayland):
 
 
 if __name__ == '__main__':
-    sys.exit(pytest.main(args=[__file__]))
+    with tempfile.TemporaryDirectory() as tmpdir:
+        # libxkbcommon has fallbacks when XDG_CONFIG_HOME isn't set so we need
+        # to override it with a known (empty) directory. Otherwise our test
+        # behavior depends on the system the test is run on.
+        os.environ['XDG_CONFIG_HOME'] = tmpdir
+
+        sys.exit(pytest.main(args=[__file__]))