on_rm_rf_error: ignore os.open (no warning) (#6074)
on_rm_rf_error: ignore os.open (no warning)
This commit is contained in:
		
						commit
						7ed33996f1
					
				|  | @ -0,0 +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``. | ||||||
|  | @ -68,13 +68,14 @@ def on_rm_rf_error(func, path: str, exc, *, start_path: Path) -> bool: | ||||||
|         return False |         return False | ||||||
| 
 | 
 | ||||||
|     if func not in (os.rmdir, os.remove, os.unlink): |     if func not in (os.rmdir, os.remove, os.unlink): | ||||||
|         warnings.warn( |         if func not in (os.open,): | ||||||
|             PytestWarning( |             warnings.warn( | ||||||
|                 "(rm_rf) unknown function {} when removing {}:\n{}: {}".format( |                 PytestWarning( | ||||||
|                     path, func, exctype, excvalue |                     "(rm_rf) unknown function {} when removing {}:\n{}: {}".format( | ||||||
|  |                         func, path, exctype, excvalue | ||||||
|  |                     ) | ||||||
|                 ) |                 ) | ||||||
|             ) |             ) | ||||||
|         ) |  | ||||||
|         return False |         return False | ||||||
| 
 | 
 | ||||||
|     # Chmod + retry. |     # Chmod + retry. | ||||||
|  |  | ||||||
|  | @ -388,11 +388,21 @@ class TestRmRf: | ||||||
|         assert not on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path) |         assert not on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path) | ||||||
| 
 | 
 | ||||||
|         # unknown function |         # unknown function | ||||||
|         with pytest.warns(pytest.PytestWarning): |         with pytest.warns( | ||||||
|  |             pytest.PytestWarning, | ||||||
|  |             match=r"^\(rm_rf\) unknown function None when removing .*foo.txt:\nNone: ", | ||||||
|  |         ): | ||||||
|             exc_info = (None, PermissionError(), None) |             exc_info = (None, PermissionError(), None) | ||||||
|             on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path) |             on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path) | ||||||
|             assert fn.is_file() |             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) |         exc_info = (None, PermissionError(), None) | ||||||
|         on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path) |         on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path) | ||||||
|         assert not fn.is_file() |         assert not fn.is_file() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue