Skip to content

Commit 7ed3399

Browse files
authored
on_rm_rf_error: ignore os.open (no warning) (#6074)
on_rm_rf_error: ignore os.open (no warning)
2 parents e670ff7 + 2adc84e commit 7ed3399

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

changelog/6074.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytester: fix order of arguments in ``rm_rf`` warning when cleaning up temporary directories, and do not emit warnings for errors with ``os.open``.

src/_pytest/pathlib.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ def on_rm_rf_error(func, path: str, exc, *, start_path: Path) -> bool:
6868
return False
6969

7070
if func not in (os.rmdir, os.remove, os.unlink):
71-
warnings.warn(
72-
PytestWarning(
73-
"(rm_rf) unknown function {} when removing {}:\n{}: {}".format(
74-
path, func, exctype, excvalue
71+
if func not in (os.open,):
72+
warnings.warn(
73+
PytestWarning(
74+
"(rm_rf) unknown function {} when removing {}:\n{}: {}".format(
75+
func, path, exctype, excvalue
76+
)
7577
)
7678
)
77-
)
7879
return False
7980

8081
# Chmod + retry.

testing/test_tmpdir.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,21 @@ def test_on_rm_rf_error(self, tmp_path):
388388
assert not on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)
389389

390390
# unknown function
391-
with pytest.warns(pytest.PytestWarning):
391+
with pytest.warns(
392+
pytest.PytestWarning,
393+
match=r"^\(rm_rf\) unknown function None when removing .*foo.txt:\nNone: ",
394+
):
392395
exc_info = (None, PermissionError(), None)
393396
on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)
394397
assert fn.is_file()
395398

399+
# ignored function
400+
with pytest.warns(None) as warninfo:
401+
exc_info = (None, PermissionError(), None)
402+
on_rm_rf_error(os.open, str(fn), exc_info, start_path=tmp_path)
403+
assert fn.is_file()
404+
assert not [x.message for x in warninfo]
405+
396406
exc_info = (None, PermissionError(), None)
397407
on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
398408
assert not fn.is_file()

0 commit comments

Comments
 (0)