Skip to content

Commit 2fb8c64

Browse files
committed
Move permission_error_tmpdir skips to test cases
This moves test skipping logic from the permission_error_tmpdir fixture to the two TestRmtree test case methods that use it. This produces some duplication, which is undesirable, but it makes it so that which tests are skipped under what conditions is immediately clear, easy to identify as skipping logic (which is usually achieved by decoration), and clear in its relationship to the skipping logic associated with other TestRmtree test cases.
1 parent aa1799f commit 2fb8c64

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

test/test_util.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@
4646
@pytest.fixture
4747
def permission_error_tmpdir(tmp_path):
4848
"""Fixture to test permissions errors situations where they are not overcome."""
49-
if sys.platform == "cygwin":
50-
raise SkipTest("Cygwin can't set the permissions that make the test meaningful.")
51-
if sys.version_info < (3, 8):
52-
raise SkipTest("In 3.7, TemporaryDirectory doesn't clean up after weird permissions.")
53-
5449
td = tmp_path / "testdir"
5550
td.mkdir()
5651
(td / "x").write_bytes(b"")
@@ -107,6 +102,14 @@ def test_deletes_dir_with_readonly_files(self, tmp_path):
107102

108103
assert not td.exists()
109104

105+
@pytest.mark.skipif(
106+
sys.platform == "cygwin",
107+
reason="Cygwin can't set the permissions that make the test meaningful.",
108+
)
109+
@pytest.mark.skipif(
110+
sys.version_info < (3, 8),
111+
reason="In 3.7, TemporaryDirectory doesn't clean up after weird permissions.",
112+
)
110113
def test_wraps_perm_error_if_enabled(self, mocker, permission_error_tmpdir):
111114
"""rmtree wraps PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is true."""
112115
# Access the module through sys.modules so it is unambiguous which module's
@@ -122,6 +125,14 @@ def test_wraps_perm_error_if_enabled(self, mocker, permission_error_tmpdir):
122125
with pytest.raises(SkipTest):
123126
rmtree(permission_error_tmpdir)
124127

128+
@pytest.mark.skipif(
129+
sys.platform == "cygwin",
130+
reason="Cygwin can't set the permissions that make the test meaningful.",
131+
)
132+
@pytest.mark.skipif(
133+
sys.version_info < (3, 8),
134+
reason="In 3.7, TemporaryDirectory doesn't clean up after weird permissions.",
135+
)
125136
def test_does_not_wrap_perm_error_unless_enabled(self, mocker, permission_error_tmpdir):
126137
"""rmtree does not wrap PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is false."""
127138
# See comments in test_wraps_perm_error_if_enabled for details about patching.

0 commit comments

Comments
 (0)