From 2fb8c64a898e4c4bf93febadffa216c8a6ff2411 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Tue, 24 Oct 2023 09:57:05 -0400 Subject: [PATCH] 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. --- test/test_util.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/test_util.py b/test/test_util.py index a02ca0cce..1147676bc 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -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"") @@ -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 @@ -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.