Skip to content

Commit d9fd704

Browse files
RonnyPfannschmidtCursor AIclaude
committed
test: add coverage for _chmod_rwx OSError and recursion guard paths
- Test _chmod_rwx returns False on nonexistent path (OSError branch) - Test _chmod_rwx returns False when permissions already sufficient - Test os.open handler returns False when chmod is ineffective Co-authored-by: Cursor AI <ai@cursor.sh> Co-authored-by: Anthropic Claude Sonnet 4 <claude@anthropic.com>
1 parent 58485d7 commit d9fd704

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

testing/test_tmpdir.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from _pytest import pathlib
1515
from _pytest.config import Config
1616
from _pytest.monkeypatch import MonkeyPatch
17+
from _pytest.pathlib import _chmod_rwx
1718
from _pytest.pathlib import cleanup_numbered_dir
1819
from _pytest.pathlib import create_cleanup_lock
1920
from _pytest.pathlib import make_numbered_dir
@@ -668,6 +669,35 @@ def test_on_rm_rf_error_os_open_parent_perms(self, tmp_path: Path) -> None:
668669
assert not child.exists()
669670
assert not [x.message for x in w]
670671

672+
def test_chmod_rwx_returns_false_on_nonexistent_path(self, tmp_path: Path) -> None:
673+
"""_chmod_rwx returns False when the path doesn't exist (OSError)."""
674+
nonexistent = tmp_path / "does_not_exist"
675+
assert _chmod_rwx(str(nonexistent)) is False
676+
677+
def test_chmod_rwx_returns_false_when_already_sufficient(
678+
self, tmp_path: Path
679+
) -> None:
680+
"""_chmod_rwx returns False when permissions are already sufficient."""
681+
d = tmp_path / "dir"
682+
d.mkdir(mode=0o700)
683+
assert _chmod_rwx(str(d)) is False
684+
685+
f = tmp_path / "file"
686+
f.touch(mode=0o600)
687+
assert _chmod_rwx(str(f)) is False
688+
689+
def test_on_rm_rf_error_os_open_returns_false_when_chmod_ineffective(
690+
self, tmp_path: Path
691+
) -> None:
692+
"""os.open handler returns False when neither parent nor path chmod
693+
changes anything (recursion guard)."""
694+
adir = tmp_path / "dir"
695+
adir.mkdir(mode=0o700)
696+
exc_info = PermissionError()
697+
result = on_rm_rf_error(os.open, str(adir), exc_info, start_path=tmp_path)
698+
assert result is False
699+
assert adir.exists()
700+
671701

672702
def attempt_symlink_to(path, to_path):
673703
"""Try to make a symlink from "path" to "to_path", skipping in case this platform

0 commit comments

Comments
 (0)