mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
SERVER-33737 Fix logger override for DynamicJSTestCase
This commit is contained in:
parent
b0b654ad5c
commit
37eab69b76
@ -40,9 +40,6 @@ class BackgroundInitialSync(interface.Hook):
|
||||
fixture.__class__.__name__))
|
||||
|
||||
description = "Background Initial Sync"
|
||||
# js_filename = os.path.join("jstests", "hooks", "run_initial_sync_node_validation.js")
|
||||
# jsfile.JSHook.__init__(self, hook_logger, fixture, js_filename,
|
||||
# description, shell_options)
|
||||
interface.Hook.__init__(self, hook_logger, fixture, description)
|
||||
|
||||
self.use_resync = use_resync
|
||||
|
@ -44,6 +44,14 @@ class DynamicJSTestCase(interface.DynamicTestCase):
|
||||
base_test_name, hook)
|
||||
self._js_test = jstest.JSTestCase(logger, js_filename, shell_options=shell_options)
|
||||
|
||||
def override_logger(self, new_logger):
|
||||
interface.DynamicTestCase.override_logger(self, new_logger)
|
||||
self._js_test.override_logger(new_logger)
|
||||
|
||||
def reset_logger(self):
|
||||
interface.DynamicTestCase.reset_logger(self)
|
||||
self._js_test.reset_logger()
|
||||
|
||||
def configure(self, fixture, *args, **kwargs): # pylint: disable=unused-argument
|
||||
interface.DynamicTestCase.configure(self, fixture, *args, **kwargs)
|
||||
self._js_test.configure(fixture, *args, **kwargs)
|
||||
|
@ -117,10 +117,7 @@ class TestReport(unittest.TestResult):
|
||||
command, test.logger)
|
||||
test_info.url_endpoint = test_logger.url_endpoint
|
||||
|
||||
# TestReport.combine() doesn't access the '__original_loggers' attribute, so we don't bother
|
||||
# protecting it with the lock.
|
||||
self.__original_loggers[test_info.test_id] = test.logger
|
||||
test.logger = test_logger
|
||||
test.override_logger(test_logger)
|
||||
|
||||
def stopTest(self, test):
|
||||
"""
|
||||
@ -144,10 +141,7 @@ class TestReport(unittest.TestResult):
|
||||
logging.flush.close_later(handler)
|
||||
|
||||
# Restore the original logger for the test.
|
||||
#
|
||||
# TestReport.combine() doesn't access the '__original_loggers' attribute, so we don't bother
|
||||
# protecting it with the lock.
|
||||
test.logger = self.__original_loggers.pop(test.id())
|
||||
test.reset_logger()
|
||||
|
||||
def addError(self, test, err):
|
||||
"""
|
||||
@ -368,10 +362,6 @@ class TestReport(unittest.TestResult):
|
||||
self.num_errored = 0
|
||||
self.num_interrupted = 0
|
||||
|
||||
# TestReport.combine() doesn't access the '__original_loggers' attribute, so we don't bother
|
||||
# protecting it with the lock.
|
||||
self.__original_loggers = {}
|
||||
|
||||
def _find_test_info(self, test):
|
||||
"""
|
||||
Returns the status and timing information associated with
|
||||
|
@ -55,6 +55,9 @@ class TestCase(unittest.TestCase):
|
||||
# logger is an instance of TestQueueLogger. When the TestCase is created by a hook
|
||||
# implementation it is an instance of BaseLogger.
|
||||
self.logger = logger
|
||||
# Used to store the logger when overridden by a test logger in Report.startTest().
|
||||
self._original_logger = None
|
||||
|
||||
self.test_kind = test_kind
|
||||
self.test_name = test_name
|
||||
|
||||
@ -87,6 +90,22 @@ class TestCase(unittest.TestCase):
|
||||
def shortDescription(self):
|
||||
return "%s %s" % (self.test_kind, self.test_name)
|
||||
|
||||
def override_logger(self, new_logger):
|
||||
"""
|
||||
Overrides this instance's logger with a new logger.
|
||||
|
||||
This method is used by the repport to set the test logger.
|
||||
"""
|
||||
assert not self._original_logger, "Logger already overridden"
|
||||
self._original_logger = self.logger
|
||||
self.logger = new_logger
|
||||
|
||||
def reset_logger(self):
|
||||
"""Resets this instance's logger to its original value."""
|
||||
assert self._original_logger, "Logger was not overridden"
|
||||
self.logger = self._original_logger
|
||||
self._original_logger = None
|
||||
|
||||
def configure(self, fixture, *args, **kwargs): # pylint: disable=unused-argument
|
||||
"""
|
||||
Stores 'fixture' as an attribute for later use during execution.
|
||||
|
Loading…
Reference in New Issue
Block a user