@@ -38,21 +38,35 @@ def ensure_reset_dir(path):
38
38
path .mkdir ()
39
39
40
40
41
- def on_rm_rf_error (func , path : str , exc , * , start_path ):
42
- """Handles known read-only errors during rmtree."""
43
- excvalue = exc [1 ]
41
+ def on_rm_rf_error (func , path : str , exc , * , start_path ) -> bool :
42
+ """Handles known read-only errors during rmtree.
43
+
44
+ The returned value is used only by our own tests.
45
+ """
46
+ exctype , excvalue = exc [:2 ]
47
+
48
+ # another process removed the file in the middle of the "rm_rf" (xdist for example)
49
+ # more context: https://github.com/pytest-dev/pytest/issues/5974#issuecomment-543799018
50
+ if isinstance (excvalue , FileNotFoundError ):
51
+ return False
44
52
45
53
if not isinstance (excvalue , PermissionError ):
46
54
warnings .warn (
47
- PytestWarning ("(rm_rf) error removing {}: {}" .format (path , excvalue ))
55
+ PytestWarning (
56
+ "(rm_rf) error removing {}\n {}: {}" .format (path , exctype , excvalue )
57
+ )
48
58
)
49
- return
59
+ return False
50
60
51
61
if func not in (os .rmdir , os .remove , os .unlink ):
52
62
warnings .warn (
53
- PytestWarning ("(rm_rf) error removing {}: {}" .format (path , excvalue ))
63
+ PytestWarning (
64
+ "(rm_rf) unknown function {} when removing {}:\n {}: {}" .format (
65
+ path , func , exctype , excvalue
66
+ )
67
+ )
54
68
)
55
- return
69
+ return False
56
70
57
71
# Chmod + retry.
58
72
import stat
@@ -73,6 +87,7 @@ def chmod_rw(p: str):
73
87
chmod_rw (str (path ))
74
88
75
89
func (path )
90
+ return True
76
91
77
92
78
93
def rm_rf (path : Path ):
0 commit comments