Write to log the begin and the end of every test case.
Change-Id: Id5b07b30be076929cb8d82b5892a0ea71ce57c7f
This commit is contained in:
parent
798a175ac9
commit
91964b910a
@ -33,8 +33,9 @@ class CaptureLogFixture(_fixture.SharedFixture):
|
||||
logger = logging.root
|
||||
handler = None
|
||||
|
||||
def __init__(self, logger=None, level=None):
|
||||
def __init__(self, test_case_id, logger=None, level=None):
|
||||
super(CaptureLogFixture, self).__init__()
|
||||
self.test_case_id = test_case_id
|
||||
if logger:
|
||||
self.logger = logger
|
||||
if level:
|
||||
@ -42,8 +43,10 @@ class CaptureLogFixture(_fixture.SharedFixture):
|
||||
|
||||
def setup_fixture(self):
|
||||
self.handler = handler = CaptureLogHandler(level=self.level)
|
||||
self.logger.addHandler(handler)
|
||||
self.addCleanup(self.logger.removeHandler, handler)
|
||||
self.logger.addHandler(handler)
|
||||
LOG.debug('--- BEGIN %s ---', self.test_case_id)
|
||||
self.addCleanup(LOG.debug, '--- END %s ---', self.test_case_id)
|
||||
|
||||
def getDetails(self):
|
||||
handler = self.handler
|
||||
@ -84,6 +87,7 @@ class CaptureLogTest(testtools.TestCase):
|
||||
capture_log_logger = logging.root
|
||||
|
||||
def setUp(self):
|
||||
self.useFixture(CaptureLogFixture(level=self.capture_log_level,
|
||||
self.useFixture(CaptureLogFixture(test_case_id=self.id(),
|
||||
level=self.capture_log_level,
|
||||
logger=self.capture_log_logger))
|
||||
super(CaptureLogTest, self).setUp()
|
||||
|
@ -26,7 +26,7 @@ LOG = log.getLogger(__name__)
|
||||
class CapureLogTest(unit.TobikoUnitTest):
|
||||
|
||||
def test_capture_log_content(self):
|
||||
with tobiko.CaptureLogFixture() as capture:
|
||||
with tobiko.CaptureLogFixture(test_case_id=self.id()) as capture:
|
||||
LOG.warning('Some debug line')
|
||||
content = capture.getDetails()['log']
|
||||
self.assertEqual('Some debug line\n', content.as_text())
|
||||
logged_lines = capture.getDetails()['log'].as_text().splitlines()
|
||||
self.assertIn('Some debug line', logged_lines)
|
||||
|
Loading…
Reference in New Issue
Block a user