From 5045f05107594782121888441c8ed22b0d537e6d Mon Sep 17 00:00:00 2001 From: Tomer Shalev Date: Sun, 7 Aug 2022 08:44:44 +0300 Subject: [PATCH] Use tempfile contextmanager in with_tmpdir --- fail2ban/tests/utils.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fail2ban/tests/utils.py b/fail2ban/tests/utils.py index 8bcc1431..e03c83d0 100644 --- a/fail2ban/tests/utils.py +++ b/fail2ban/tests/utils.py @@ -235,12 +235,8 @@ def with_tmpdir(f): """ @wraps(f) def wrapper(self, *args, **kwargs): - tmp = tempfile.mkdtemp(prefix="f2b-temp") - try: + with tempfile.TemporaryDirectory(prefix="f2b-temp") as tmp: return f(self, tmp, *args, **kwargs) - finally: - # clean up - shutil.rmtree(tmp) return wrapper def with_alt_time(f):