From 6cf63195fa5f0490746a89c65a42a379ced68d47 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Thu, 18 Jun 2015 13:04:43 -0400 Subject: [PATCH] Disable profiler for unit tests osprofiler should not run for unit tests. This makes stack traces harder to debug, and generally complicates things, with no benefit. The backup tests were already doing this, so port that method to the base Cinder test class. Closes-Bug: #1394785 Closes-Bug: #1447400 Change-Id: Ifcaaf365aaab24c6fa2a6eca58f546860124f1fc --- cinder/test.py | 14 ++++++++++++++ cinder/tests/unit/test_backup.py | 7 +------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cinder/test.py b/cinder/test.py index f5db6bdec..ec025b1bf 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -224,6 +224,20 @@ class TestCase(testtools.TestCase): 'cinder/tests/unit/policy.json'), group='oslo_policy') + self._disable_osprofiler() + + def _disable_osprofiler(self): + """Disable osprofiler. + + osprofiler should not run for unit tests. + """ + + side_effect = lambda value: value + mock_decorator = mock.MagicMock(side_effect=side_effect) + p = mock.patch("osprofiler.profiler.trace_cls", + return_value=mock_decorator) + p.start() + def _common_cleanup(self): """Runs after each test method to tear down test environment.""" diff --git a/cinder/tests/unit/test_backup.py b/cinder/tests/unit/test_backup.py index 66bccac21..1748a107a 100644 --- a/cinder/tests/unit/test_backup.py +++ b/cinder/tests/unit/test_backup.py @@ -47,12 +47,7 @@ class BaseBackupTest(test.TestCase): super(BaseBackupTest, self).setUp() vol_tmpdir = tempfile.mkdtemp() self.flags(volumes_dir=vol_tmpdir) - with mock.patch("osprofiler.profiler.trace_cls") as mock_trace_cls: - side_effect = lambda value: value - mock_decorator = mock.MagicMock(side_effect=side_effect) - mock_trace_cls.return_value = mock_decorator - self.backup_mgr = \ - importutils.import_object(CONF.backup_manager) + self.backup_mgr = importutils.import_object(CONF.backup_manager) self.backup_mgr.host = 'testhost' self.ctxt = context.get_admin_context() self.backup_mgr.driver.set_initialized() -- 2.45.2