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) @wraps(f)
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
tmp = tempfile.mkdtemp(prefix="f2b-temp") with tempfile.TemporaryDirectory(prefix="f2b-temp") as tmp:
try:
return f(self, tmp, *args, **kwargs) return f(self, tmp, *args, **kwargs)
finally:
# clean up
shutil.rmtree(tmp)
return wrapper return wrapper
def with_alt_time(f): def with_alt_time(f):