tests: Cleanup on failure of in_tempdir

Otherwise other tests will also fail when they try to run from the wrong
directory.

(cherry picked from commit 65b8a2be68)
(cherry picked from commit 94e2651cf6)
This commit is contained in:
Brian C. Lane 2019-04-15 14:06:48 -07:00
parent b94fdddc7c
commit 5230b8d30e
2 changed files with 10 additions and 6 deletions

View File

@ -84,7 +84,9 @@ def in_tempdir(prefix='tmp'):
oldcwd = os.getcwd() oldcwd = os.getcwd()
tmpdir = tempfile.mkdtemp(prefix=prefix) tmpdir = tempfile.mkdtemp(prefix=prefix)
os.chdir(tmpdir) os.chdir(tmpdir)
try:
yield yield
finally:
os.chdir(oldcwd) os.chdir(oldcwd)
shutil.rmtree(tmpdir) shutil.rmtree(tmpdir)

View File

@ -1544,7 +1544,9 @@ def in_tempdir(prefix='tmp'):
oldcwd = os.getcwd() oldcwd = os.getcwd()
tmpdir = tempfile.mkdtemp(prefix=prefix) tmpdir = tempfile.mkdtemp(prefix=prefix)
os.chdir(tmpdir) os.chdir(tmpdir)
try:
yield yield
finally:
os.chdir(oldcwd) os.chdir(oldcwd)
shutil.rmtree(tmpdir) shutil.rmtree(tmpdir)