From daaa5ff5c567d3faa8fba8bbe0079bd186e73853 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sat, 9 Jul 2016 11:38:32 -0400 Subject: [PATCH] Don't create real config/data dirs from tests. Running the tests would create ~/.config/qute_test and ~/.local/share/qute_test on the user's machine. The test_standardir module needed a bit more mocking to prevent it from cluttering the user's machine. Two tests that created the data dir were fixed by passing basedir in args, and one test that created the config dir was fixed by patching os.makedirs to a noop. --- tests/unit/utils/test_standarddir.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index 4c77e1d57..883b9d856 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -195,8 +195,10 @@ class TestArguments: standarddir.init(args) assert standarddir.data() == testcase.expected - def test_confdir_none(self): + def test_confdir_none(self, mocker): """Test --confdir with None given.""" + # patch makedirs to a noop so we don't really create a directory + mocker.patch('qutebrowser.utils.standarddir.os.makedirs') args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None, basedir=None) standarddir.init(args) @@ -326,12 +328,16 @@ class TestSystemData: assert standarddir.system_data() == "/usr/share/qutebrowser" @pytest.mark.linux - def test_system_datadir_not_exist_linux(self, monkeypatch): + def test_system_datadir_not_exist_linux(self, monkeypatch, tmpdir): """Test that system-wide path isn't used on linux if path not exist.""" + args = types.SimpleNamespace(basedir=str(tmpdir)) + standarddir.init(args) monkeypatch.setattr(os.path, 'exists', lambda path: False) assert standarddir.system_data() == standarddir.data() - def test_system_datadir_unsupportedos(self, monkeypatch): + def test_system_datadir_unsupportedos(self, monkeypatch, tmpdir): """Test that system-wide path is not used on non-Linux OS.""" + args = types.SimpleNamespace(basedir=str(tmpdir)) + standarddir.init(args) monkeypatch.setattr('sys.platform', "potato") assert standarddir.system_data() == standarddir.data()