def testCapture(self): s = StringIO() with logging_util.CaptureLogs(s): logging.fatal('test') # Only assert ends with, since the logging message by default has the date # in it. self.assertTrue(s.getvalue().endswith('test\n'))
def CaptureLogsAsArtifacts(results, test_name): file_name = '' try: with tempfile.NamedTemporaryFile( prefix='test_', suffix='.log', delete=False) as file_obj: file_name = file_obj.name with logging_util.CaptureLogs(file_obj): yield finally: if file_name: results.AddArtifact(test_name, 'logs', file_name)
def CaptureLogsAsArtifacts(results): with results.CreateArtifact('logs.txt') as log_file: with logging_util.CaptureLogs(log_file): yield
def CaptureLogsAsArtifacts(results, test_name): with results.CreateArtifact(test_name, 'logs') as log_file: with logging_util.CaptureLogs(log_file): yield
def testCapture(self): s = StringIO.StringIO() with logging_util.CaptureLogs(s): logging.fatal('test') self.assertEqual(s.getvalue(), 'test\n')