@@ -38,21 +38,35 @@ def ensure_reset_dir(path):
3838 path .mkdir ()
3939
4040
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
4452
4553 if not isinstance (excvalue , PermissionError ):
4654 warnings .warn (
47- PytestWarning ("(rm_rf) error removing {}: {}" .format (path , excvalue ))
55+ PytestWarning (
56+ "(rm_rf) error removing {}\n {}: {}" .format (path , exctype , excvalue )
57+ )
4858 )
49- return
59+ return False
5060
5161 if func not in (os .rmdir , os .remove , os .unlink ):
5262 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+ )
5468 )
55- return
69+ return False
5670
5771 # Chmod + retry.
5872 import stat
@@ -73,6 +87,7 @@ def chmod_rw(p: str):
7387 chmod_rw (str (path ))
7488
7589 func (path )
90+ return True
7691
7792
7893def rm_rf (path : Path ):
0 commit comments