From 94e2651cf6b1ace857f3127bfb171e9fe5ec1d72 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 15 Apr 2019 14:06:48 -0700 Subject: [PATCH] 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 65b8a2be6857fa9ec293ee64f494869fd8ff398e) --- tests/pylorax/test_ltmpl.py | 8 +++++--- tests/pylorax/test_server.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) 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 315ef710..cc6a2773 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -1559,9 +1559,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"""