Nir Soffer has uploaded a new change for review.
Change subject: tests: Fix patchDecorators so decorated function will actually run ......................................................................
tests: Fix patchDecorators so decorated function will actually run
Commit 5c5a0d9c5 introduced a fancy decorator for cleaning up the mess when we monkey patch conifguratiors. Unfortunatly, this decorator has an unexpected side effect, of *not* running the decorated function, so the test would always pass, even if the code is broken.
This patch replaces this decorator with a much simpler one that let the real decorator (MonkeyPatch) do the right thing.
Change-Id: I1c4be2a15160be48b56a7df2f406e4e0afabd11e Signed-off-by: Nir Soffer nsoffer@redhat.com --- M tests/toolTests.py 1 file changed, 22 insertions(+), 10 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/53/34153/1
diff --git a/tests/toolTests.py b/tests/toolTests.py index ee0f750..daba9fe 100644 --- a/tests/toolTests.py +++ b/tests/toolTests.py @@ -34,7 +34,6 @@ from testlib import VdsmTestCase from testValidation import ValidateRunningAsRoot from unittest import TestCase -import functools import tempfile import os import shutil @@ -78,15 +77,28 @@
def patchConfigurators(mockConfigurers): - def decorator(f): - @functools.wraps(f) - def wrapper(*args, **kw): - monkeypatch.MonkeyPatch( - configurator, - '_CONFIGURATORS', - dict((m.name, m) for m in mockConfigurers)) - return wrapper - return decorator + return monkeypatch.MonkeyPatch( + configurator, + '_CONFIGURATORS', + dict((m.name, m) for m in mockConfigurers)) + + +class PatchConfiguratorsTests(VdsmTestCase): + + def testPatch(self): + self.configurator = MockModuleConfigurator('a') + self.function_was_run = False + + @patchConfigurators((self.configurator,)) + def function(): + self.function_was_run = True + conf = configurator._CONFIGURATORS[self.configurator.name] + self.assertTrue(conf is self.configurator) + + self.assertFalse(self.configurator.name in configurator._CONFIGURATORS) + function() + self.assertTrue(self.function_was_run) + self.assertFalse(self.configurator.name in configurator._CONFIGURATORS)
class ConfiguratorTests(VdsmTestCase):