diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-10-13 16:59:13 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-10-13 18:05:25 +0200 |
commit | 779af13764ae694af907145901727f7b730bfc49 (patch) | |
tree | af2344e0c06d1e1a9b421e5207ec5e456ea806b7 | |
parent | 2a61e0dae003591d01821b25b59987b168fbbddb (diff) | |
download | qutebrowser-779af13764ae694af907145901727f7b730bfc49.tar.gz qutebrowser-779af13764ae694af907145901727f7b730bfc49.zip |
tests: Avoid mocking in CACHEDIR.tag test
See #5787
-rw-r--r-- | tests/helpers/fixtures.py | 13 | ||||
-rw-r--r-- | tests/unit/misc/test_editor.py | 11 | ||||
-rw-r--r-- | tests/unit/utils/test_standarddir.py | 6 |
3 files changed, 15 insertions, 15 deletions
diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index 7ab6956f0..2183ac1d1 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -709,3 +709,16 @@ def state_config(data_tmpdir, monkeypatch): state = configfiles.StateConfig() monkeypatch.setattr(configfiles, 'state', state) return state + + +@pytest.fixture +def unwritable_tmp_path(tmp_path): + tmp_path.chmod(0) + if os.access(str(tmp_path), os.W_OK): + # Docker container or similar + pytest.skip("Directory was still writable") + + yield tmp_path + + # Make sure pytest can clean up the tmp_path + tmp_path.chmod(0o755) diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py index 323ac1b21..694e6d204 100644 --- a/tests/unit/misc/test_editor.py +++ b/tests/unit/misc/test_editor.py @@ -137,17 +137,6 @@ class TestFileHandling: msg = message_mock.getmsg(usertypes.MessageLevel.error) assert msg.text.startswith("Failed to read back edited file: ") - @pytest.fixture - def unwritable_tmp_path(self, tmp_path): - tmp_path.chmod(0) - if os.access(str(tmp_path), os.W_OK): - # Docker container or similar - pytest.skip("File was still writable") - - yield tmp_path - - tmp_path.chmod(0o755) - def test_unwritable(self, monkeypatch, message_mock, editor, unwritable_tmp_path, caplog): """Test file handling when the initial file is not writable.""" diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index 064c51b30..ea65b7cc4 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -308,14 +308,12 @@ class TestInitCacheDirTag: # http://www.brynosaurus.com/cachedir/ """).lstrip() - def test_open_oserror(self, caplog, tmpdir, mocker, monkeypatch): + def test_open_oserror(self, caplog, unwritable_tmp_path, monkeypatch): """Test creating a new CACHEDIR.TAG.""" - monkeypatch.setattr(standarddir, 'cache', lambda: str(tmpdir)) - mocker.patch('builtins.open', side_effect=OSError) + monkeypatch.setattr(standarddir, 'cache', lambda: str(unwritable_tmp_path)) with caplog.at_level(logging.ERROR, 'init'): standarddir._init_cachedir_tag() assert caplog.messages == ['Failed to create CACHEDIR.TAG'] - assert not tmpdir.listdir() class TestCreatingDir: |