From 1f71520bb2a5bbddb69047a0ca5539cb0bacd0e6 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 10 Jul 2016 07:44:58 -0400 Subject: [PATCH] Prevent tests from creating cachedir tag. Running test_standarddir would pollute the user's home with `~/.cache/qute_test`. The `no_cachedir_tag` fixture was supposed to prevent this, but was not working because [usefixtures does not work on fixtures] (https://github.com/pytest-dev/pytest/issues/1014). This fixes the fixture to actually prevent cachedir creation, but applies it to tests individually (or by class) rather than with autouse because the cachedir tests cannot pass if it is working. --- tests/unit/utils/test_standarddir.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index 883b9d856..bc99e6f7c 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -52,15 +52,15 @@ def no_cachedir_tag(monkeypatch): lambda: None) -@pytest.yield_fixture(autouse=True) -@pytest.mark.usefixtures('no_cachedir_tag') -def reset_standarddir(): +@pytest.yield_fixture +def reset_standarddir(no_cachedir_tag): """Clean up standarddir arguments before and after each test.""" standarddir.init(None) yield standarddir.init(None) +@pytest.mark.usefixtures('reset_standarddir') @pytest.mark.parametrize('data_subdir, config_subdir, expected', [ ('foo', 'foo', 'foo/data'), ('foo', 'bar', 'foo'), @@ -80,6 +80,7 @@ def test_get_fake_windows_equal_dir(data_subdir, config_subdir, expected, assert standarddir.data() == expected +@pytest.mark.usefixtures('reset_standarddir') class TestWritableLocation: """Tests for _writable_location.""" @@ -100,7 +101,7 @@ class TestWritableLocation: assert '\\' in loc -@pytest.mark.usefixtures('no_cachedir_tag') +@pytest.mark.usefixtures('reset_standarddir') class TestStandardDir: """Tests for standarddir.""" @@ -159,7 +160,7 @@ class TestStandardDir: DirArgTest = collections.namedtuple('DirArgTest', 'arg, expected') -@pytest.mark.usefixtures('no_cachedir_tag') +@pytest.mark.usefixtures('reset_standarddir') class TestArguments: """Tests with confdir/cachedir/datadir arguments.""" @@ -274,6 +275,7 @@ class TestInitCacheDirTag: assert not tmpdir.listdir() +@pytest.mark.usefixtures('reset_standarddir') class TestCreatingDir: """Make sure inexistent directories are created properly.""" @@ -317,6 +319,7 @@ class TestCreatingDir: func() +@pytest.mark.usefixtures('reset_standarddir') class TestSystemData: """Test system data path."""