Use tempfile contextmanager in with_tmpdir

pull/3328/head
Tomer Shalev 2022-08-07 08:44:44 +03:00
parent 3c22ae161c
commit 5045f05107
1 changed files with 1 additions and 5 deletions

View File

@ -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):