diff --git a/tests/pylorax/test_ltmpl.py b/tests/pylorax/test_ltmpl.py index 7af91fdd..6afc0a46 100644 --- a/tests/pylorax/test_ltmpl.py +++ b/tests/pylorax/test_ltmpl.py @@ -84,9 +84,11 @@ def in_tempdir(prefix='tmp'): oldcwd = os.getcwd() tmpdir = tempfile.mkdtemp(prefix=prefix) os.chdir(tmpdir) - yield - os.chdir(oldcwd) - shutil.rmtree(tmpdir) + try: + yield + finally: + os.chdir(oldcwd) + shutil.rmtree(tmpdir) def makeFakeRPM(repo_dir, name, epoch, version, release, files=None): """Make a fake rpm file in repo_dir""" diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index 3178d22d..d9c4c433 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -1544,9 +1544,11 @@ def in_tempdir(prefix='tmp'): oldcwd = os.getcwd() tmpdir = tempfile.mkdtemp(prefix=prefix) os.chdir(tmpdir) - yield - os.chdir(oldcwd) - shutil.rmtree(tmpdir) + try: + yield + finally: + os.chdir(oldcwd) + shutil.rmtree(tmpdir) def makeFakeRPM(repo_dir, name, epoch, version, release): """Make a fake rpm file in repo_dir"""