From 294193c60549d938225a9e42b89d883e5f16827f Mon Sep 17 00:00:00 2001 From: "Kim, Vinnam" Date: Thu, 21 Sep 2023 14:08:17 +0900 Subject: [PATCH] Try rmtree() several times Signed-off-by: Kim, Vinnam --- tests/utils/test_utils.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index d9e7560491..3ab4339958 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -10,10 +10,9 @@ import tempfile import unittest import unittest.mock -import warnings from enum import Enum, auto from glob import glob -from tempfile import TemporaryDirectory +from time import sleep from typing import Any, Collection, List, Optional, Union import pytest @@ -45,15 +44,21 @@ def __enter__(self): return self.path def __exit__(self, exc_type=None, exc_value=None, traceback=None): - if self.is_dir: - try: - rmtree(self.path) - except unittest.SkipTest: - # Suppress skip test errors from git.util.rmtree - if not exc_type: - raise - else: - rmfile(self.path) + for _ in range(10): + if not os.path.exists(self.path): + return + + if self.is_dir: + try: + rmtree(self.path) + except unittest.SkipTest: + # Suppress skip test errors from git.util.rmtree + if not exc_type: + raise + else: + rmfile(self.path) + + sleep(0.5) class TestDir(FileRemover):