Commit 7a5f2601 by Remi Rampin Committed by Arun Babu Neelicattu

Don't swallow ImportError in temporary_directory()

Fixes #3026

If the context wrapped by the temporary_directory() context manager
raised ImportError (for example because distutils.util cannot be
imported, #721 #1837), it would previously keep going, causing a
RuntimeError from contextlib:

    RuntimeError: generator didn't stop after throw()
parent d6733428
......@@ -159,15 +159,15 @@ def colorize(style, text):
def temporary_directory(*args, **kwargs):
try:
from tempfile import TemporaryDirectory
with TemporaryDirectory(*args, **kwargs) as name:
yield name
except ImportError:
name = tempfile.mkdtemp(*args, **kwargs)
yield name
shutil.rmtree(name)
else:
with TemporaryDirectory(*args, **kwargs) as name:
yield name
def string_to_bool(value):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment