[oe-commits] Corneliu Stoicescu : oe-selftest: Add track_for_cleanup method to be used in cleanup tasks
git at git.openembedded.org
git at git.openembedded.org
Sun Dec 15 16:44:59 UTC 2013
Module: openembedded-core.git
Branch: master-next
Commit: 358415cf604089cc2dab547e231d062b9dc068ee
URL: http://git.openembedded.org/?p=openembedded-core.git&a=commit;h=358415cf604089cc2dab547e231d062b9dc068ee
Author: Corneliu Stoicescu <corneliux.stoicescu at intel.com>
Date: Wed Dec 11 17:09:40 2013 +0100
oe-selftest: Add track_for_cleanup method to be used in cleanup tasks
Added a track_for_cleanup(path) method that removes the given path in the
tearDown method. This mechanism can be used to make sure a file or directory
we created will be removed at the end of a test, regardless of what happens.
Signed-off-by: Corneliu Stoicescu <corneliux.stoicescu at intel.com>
Signed-off-by: Saul Wold <sgw at linux.intel.com>
---
meta/lib/oeqa/selftest/base.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/meta/lib/oeqa/selftest/base.py b/meta/lib/oeqa/selftest/base.py
index 25ca84b..fc880e9 100644
--- a/meta/lib/oeqa/selftest/base.py
+++ b/meta/lib/oeqa/selftest/base.py
@@ -9,6 +9,7 @@
import unittest
import os
import sys
+import shutil
import logging
import errno
@@ -26,6 +27,7 @@ class oeSelfTest(unittest.TestCase):
self.testinc_path = os.path.join(self.builddir, "conf/selftest.inc")
self.testlayer_path = oeSelfTest.testlayer_path
self._extra_tear_down_commands = []
+ self._track_for_cleanup = []
super(oeSelfTest, self).__init__(methodName)
def setUp(self):
@@ -60,6 +62,15 @@ class oeSelfTest(unittest.TestCase):
self.log.warning("tearDown commands have failed: %s" % ', '.join(map(str, failed_extra_commands)))
self.log.debug("Trying to move on.")
self._extra_tear_down_commands = []
+
+ if self._track_for_cleanup:
+ for path in self._track_for_cleanup:
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+ if os.path.isfile(path):
+ os.remove(path)
+ self._track_for_cleanup = []
+
self.tearDownLocal()
def tearDownLocal(self):
@@ -69,6 +80,10 @@ class oeSelfTest(unittest.TestCase):
def add_command_to_tearDown(self, command):
self.log.debug("Adding command '%s' to tearDown for this test." % command)
self._extra_tear_down_commands.append(command)
+ # add test specific files or directories to be removed in the tearDown method
+ def track_for_cleanup(self, path):
+ self.log.debug("Adding path '%s' to be cleaned up when test is over" % path)
+ self._track_for_cleanup.append(path)
# write to <builddir>/conf/selftest.inc
def write_config(self, data):
More information about the Openembedded-commits
mailing list