Пример #1
0
    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'))
Пример #2
0
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)
Пример #3
0
def CaptureLogsAsArtifacts(results):
    with results.CreateArtifact('logs.txt') as log_file:
        with logging_util.CaptureLogs(log_file):
            yield
Пример #4
0
def CaptureLogsAsArtifacts(results, test_name):
    with results.CreateArtifact(test_name, 'logs') as log_file:
        with logging_util.CaptureLogs(log_file):
            yield
Пример #5
0
    def testCapture(self):
        s = StringIO.StringIO()
        with logging_util.CaptureLogs(s):
            logging.fatal('test')

        self.assertEqual(s.getvalue(), 'test\n')