@@ -48,24 +48,38 @@ def ensure_reset_dir(path):
4848
4949
5050def on_rm_rf_error (func , path , exc , ** kwargs ):
51- """Handles known read-only errors during rmtree."""
51+ """Handles known read-only errors during rmtree.
52+
53+ The returned value is used only by our own tests.
54+ """
5255 start_path = kwargs ["start_path" ]
53- excvalue = exc [1 ]
56+ exctype , excvalue = exc [:2 ]
57+
58+ # another process removed the file in the middle of the "rm_rf" (xdist for example)
59+ # more context: https://github.com/pytest-dev/pytest/issues/5974#issuecomment-543799018
60+ if isinstance (excvalue , OSError ) and excvalue .errno == errno .ENOENT :
61+ return False
5462
5563 if not isinstance (excvalue , OSError ) or excvalue .errno not in (
5664 errno .EACCES ,
5765 errno .EPERM ,
5866 ):
5967 warnings .warn (
60- PytestWarning ("(rm_rf) error removing {}: {}" .format (path , excvalue ))
68+ PytestWarning (
69+ "(rm_rf) error removing {}\n {}: {}" .format (path , exctype , excvalue )
70+ )
6171 )
62- return
72+ return False
6373
6474 if func not in (os .rmdir , os .remove , os .unlink ):
6575 warnings .warn (
66- PytestWarning ("(rm_rf) error removing {}: {}" .format (path , excvalue ))
76+ PytestWarning (
77+ "(rm_rf) unknown function {} when removing {}:\n {}: {}" .format (
78+ path , func , exctype , excvalue
79+ )
80+ )
6781 )
68- return
82+ return False
6983
7084 # Chmod + retry.
7185 import stat
@@ -86,6 +100,7 @@ def chmod_rw(p):
86100 chmod_rw (str (path ))
87101
88102 func (path )
103+ return True
89104
90105
91106def rm_rf (path ):
0 commit comments