From e571e09f593ad6447107e36e09eb505333aa2bf9 Mon Sep 17 00:00:00 2001 From: Yusuke Kadowaki Date: Wed, 23 Nov 2022 16:55:54 +0900 Subject: [PATCH] Fix not to delete directory when policy is --- src/_pytest/tmpdir.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index c450abbc4..3fd8168b6 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -281,8 +281,7 @@ def tmp_path( policy = tmp_path_factory._retention_policy result_dict = request.node.stash[tmppath_result_key] - # "call" might be skipped so check if it exists first - if "call" not in result_dict or (policy == "failed" and result_dict["call"]): + if policy == "failed" and result_dict.get("call", True): # We do a "best effort" to remove files, but it might not be possible due to some leaked resource, # permissions, etc, in which case we ignore it. rmtree(path, ignore_errors=True)