on_rm_rf_error: ignore os.open (no warning)

Ref: https://github.com/pytest-dev/pytest/pull/6044/files#r339321752
This commit is contained in:
Daniel Hahler 2019-10-27 02:28:35 +01:00
parent 5be3a9b5ce
commit 8aa0809fbc
2 changed files with 13 additions and 5 deletions

View File

@ -68,13 +68,14 @@ def on_rm_rf_error(func, path: str, exc, *, start_path: Path) -> bool:
return False
if func not in (os.rmdir, os.remove, os.unlink):
warnings.warn(
PytestWarning(
"(rm_rf) unknown function {} when removing {}:\n{}: {}".format(
path, func, exctype, excvalue
if func not in (os.open,):
warnings.warn(
PytestWarning(
"(rm_rf) unknown function {} when removing {}:\n{}: {}".format(
path, func, exctype, excvalue
)
)
)
)
return False
# Chmod + retry.

View File

@ -393,6 +393,13 @@ class TestRmRf:
on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)
assert fn.is_file()
# ignored function
with pytest.warns(None) as warninfo:
exc_info = (None, PermissionError(), None)
on_rm_rf_error(os.open, str(fn), exc_info, start_path=tmp_path)
assert fn.is_file()
assert not [x.message for x in warninfo]
exc_info = (None, PermissionError(), None)
on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
assert not fn.is_file()