diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2015-01-27 03:44:10 +0100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2015-03-06 04:41:48 +0100 |
commit | 9a4a7b9d3e91439145e8a54c37da4a84754fe152 (patch) | |
tree | d123a5a9924d7c569adee1caac13da7e3a097e14 /python | |
parent | e3a9feb6984136172616260293130095e19051e2 (diff) | |
download | samba-9a4a7b9d3e91439145e8a54c37da4a84754fe152.tar.gz samba-9a4a7b9d3e91439145e8a54c37da4a84754fe152.tar.xz samba-9a4a7b9d3e91439145e8a54c37da4a84754fe152.zip |
Add replacement addCleanup.
Change-Id: Ie85756effde344fc4cc9b693c4a28611ea091677
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/tests/__init__.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py index 86ec3dff13..65a727aaf6 100644 --- a/python/samba/tests/__init__.py +++ b/python/samba/tests/__init__.py @@ -53,6 +53,7 @@ class TestCase(unittest.TestCase): def get_credentials(self): return cmdline_credentials + # These functions didn't exist before Python2.7: if not getattr(unittest.TestCase, "skipTest", None): def skipTest(self, reason): raise SkipTest(reason) @@ -65,6 +66,16 @@ class TestCase(unittest.TestCase): def assertIsNot(self, a, b): self.assertTrue(a is not b) + if not getattr(unittest.TestCase, "addCleanup", None): + def addCleanup(self, fn, *args, **kwargs): + self._cleanups = getattr(self, "_cleanups", []) + [ + (fn, args, kwargs)] + + def tearDown(self): + super(TestCase, self).tearDown() + for (fn, args, kwargs) in reversed(getattr(self, "_cleanups", [])): + fn(*args, **kwargs) + class LdbTestCase(unittest.TestCase): """Trivial test case for running tests against a LDB.""" |