Skip to content

Commit

Permalink
Move permission_error_tmpdir skips to test cases
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EliahKagan committed Nov 3, 2023
1 parent aa1799f commit 2fb8c64
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
@pytest.fixture
def permission_error_tmpdir(tmp_path):
"""Fixture to test permissions errors situations where they are not overcome."""
if sys.platform == "cygwin":
raise SkipTest("Cygwin can't set the permissions that make the test meaningful.")
if sys.version_info < (3, 8):
raise SkipTest("In 3.7, TemporaryDirectory doesn't clean up after weird permissions.")

td = tmp_path / "testdir"
td.mkdir()
(td / "x").write_bytes(b"")
Expand Down Expand Up @@ -107,6 +102,14 @@ def test_deletes_dir_with_readonly_files(self, tmp_path):

assert not td.exists()

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

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

0 comments on commit 2fb8c64

Please sign in to comment.