From 23810876e408253aee8ba19082abd7f07ec7925d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 15 Mar 2021 13:21:52 +0100 Subject: tests: Handle XDG_*_HOME standarddir tests For some reason, a recent change on GitHub's runners seems to explicitly set XDG_CONFIG_HOME. That breaks our tests, however, because we can't simply override HOME to control where the directories are created. Thus, make sure that XDG_*_HOME is always unset. --- tests/unit/utils/test_standarddir.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index 035ce87a3..5b24ed962 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -42,6 +42,14 @@ APPNAME = 'qute_test' pytestmark = pytest.mark.usefixtures('qapp') +@pytest.fixture +def fake_home_envvar(monkeypatch, tmp_path): + """Fake a different HOME via environment variables.""" + for k in ['XDG_DATA_HOME', 'XDG_CONFIG_HOME', 'XDG_DATA_HOME']: + monkeypatch.delenv(k, raising=False) + monkeypatch.setenv('HOME', str(tmp_path)) + + @pytest.fixture(autouse=True) def clear_standarddir_cache_and_patch(qapp, monkeypatch): """Make sure the standarddir cache is cleared before/after each test. @@ -79,10 +87,9 @@ def test_unset_organization_no_qapp(monkeypatch): @pytest.mark.fake_os('mac') @pytest.mark.posix -def test_fake_mac_config(tmpdir, monkeypatch): +def test_fake_mac_config(tmp_path, fake_home_envvar): """Test standardir.config on a fake Mac.""" - monkeypatch.setenv('HOME', str(tmpdir)) - expected = str(tmpdir) + '/.qute_test' # always with / + expected = str(tmp_path) + '/.qute_test' # always with / standarddir._init_config(args=None) assert standarddir.config() == expected @@ -175,13 +182,10 @@ class TestStandardDir: (standarddir.download, ['Downloads']), ]) @pytest.mark.linux - def test_linux_normal(self, monkeypatch, tmpdir, func, subdirs): + def test_linux_normal(self, fake_home_envvar, tmp_path, func, subdirs): """Test dirs with XDG_*_HOME not set.""" - monkeypatch.setenv('HOME', str(tmpdir)) - for var in ['DATA', 'CONFIG', 'CACHE']: - monkeypatch.delenv('XDG_{}_HOME'.format(var), raising=False) standarddir._init_dirs() - assert func() == str(tmpdir.join(*subdirs)) + assert func() == str(tmp_path.joinpath(*subdirs)) @pytest.mark.linux @pytest.mark.qt_log_ignore(r'^QStandardPaths: ') @@ -397,19 +401,17 @@ class TestSystemData: @pytest.mark.parametrize('args_kind', ['basedir', 'normal', 'none']) -def test_init(tmpdir, monkeypatch, args_kind): +def test_init(tmp_path, args_kind, fake_home_envvar): """Do some sanity checks for standarddir.init(). Things like _init_cachedir_tag() are tested in more detail in other tests. """ assert standarddir._locations == {} - monkeypatch.setenv('HOME', str(tmpdir)) - if args_kind == 'normal': args = types.SimpleNamespace(basedir=None) elif args_kind == 'basedir': - args = types.SimpleNamespace(basedir=str(tmpdir)) + args = types.SimpleNamespace(basedir=str(tmp_path)) else: assert args_kind == 'none' args = None -- cgit v1.2.3-54-g00ecf