ComponentTestBase: add a per-class toplevel temp dir
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 2 Oct 2013 13:35:32 +0000 (16:35 +0300)
committerGuido Günther <agx@sigxcpu.org>
Fri, 5 Dec 2014 14:42:15 +0000 (15:42 +0100)
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
tests/component/__init__.py

index 7abb16d12bc972f3f6b3e38ee67d583ea142ffff..44a84e20f4a98106280c1ebcd5285796120a8d5f 100644 (file)
@@ -85,6 +85,9 @@ class ComponentTestBase(object):
         # Don't let git see that we're (possibly) under a git directory
         cls.orig_env = os.environ.copy()
         os.environ['GIT_CEILING_DIRECTORIES'] = os.getcwd()
+        # Create a top-level tmpdir for the test
+        cls._tmproot = tempfile.mkdtemp(prefix='gbp_%s_' % cls.__name__,
+                                        dir='.')
 
     @classmethod
     def teardown_class(cls):
@@ -92,6 +95,9 @@ class ComponentTestBase(object):
         # Return original environment
         os.environ.clear()
         os.environ.update(cls.orig_env)
+        # Remove top-level tmpdir
+        if not os.getenv("GBP_TESTS_NOCLEAN"):
+            shutil.rmtree(cls._tmproot)
 
     def __init__(self):
         """Object initialization"""
@@ -104,7 +110,8 @@ class ComponentTestBase(object):
         """Test case setup"""
         # Change to a temporary directory
         self._orig_dir = os.getcwd()
-        self._tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
+        self._tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__,
+                                        dir=self._tmproot)
         os.chdir(self._tmpdir)
 
         self._capture_log(True)