@@ -48,24 +48,38 @@ def ensure_reset_dir(path):
48
48
49
49
50
50
def 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
+ """
52
55
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
54
62
55
63
if not isinstance (excvalue , OSError ) or excvalue .errno not in (
56
64
errno .EACCES ,
57
65
errno .EPERM ,
58
66
):
59
67
warnings .warn (
60
- PytestWarning ("(rm_rf) error removing {}: {}" .format (path , excvalue ))
68
+ PytestWarning (
69
+ "(rm_rf) error removing {}\n {}: {}" .format (path , exctype , excvalue )
70
+ )
61
71
)
62
- return
72
+ return False
63
73
64
74
if func not in (os .rmdir , os .remove , os .unlink ):
65
75
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
+ )
67
81
)
68
- return
82
+ return False
69
83
70
84
# Chmod + retry.
71
85
import stat
@@ -86,6 +100,7 @@ def chmod_rw(p):
86
100
chmod_rw (str (path ))
87
101
88
102
func (path )
103
+ return True
89
104
90
105
91
106
def rm_rf (path ):
0 commit comments