Ejemplo n.º 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'))
Ejemplo 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)
Ejemplo n.º 3
0
def CaptureLogsAsArtifacts(results):
    with results.CreateArtifact('logs.txt') as log_file:
        with logging_util.CaptureLogs(log_file):
            yield
Ejemplo n.º 4
0
def CaptureLogsAsArtifacts(results, test_name):
    with results.CreateArtifact(test_name, 'logs') as log_file:
        with logging_util.CaptureLogs(log_file):
            yield
Ejemplo n.º 5
0
    def testCapture(self):
        s = StringIO.StringIO()
        with logging_util.CaptureLogs(s):
            logging.fatal('test')

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