WIP
This commit is contained in:
parent
28a93b9eeb
commit
d6f75d2836
|
@ -5,6 +5,7 @@ from contextlib import closing, contextmanager
|
||||||
import sys
|
import sys
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
import _pytest
|
||||||
import pytest
|
import pytest
|
||||||
import py
|
import py
|
||||||
|
|
||||||
|
@ -120,14 +121,15 @@ class LogCaptureHandler(logging.StreamHandler):
|
||||||
logging.StreamHandler.emit(self, record)
|
logging.StreamHandler.emit(self, record)
|
||||||
|
|
||||||
|
|
||||||
class TerminalWriterHandler(logging.Handler):
|
class TerminalReporterHandler(logging.Handler):
|
||||||
def __init__(self):
|
def __init__(self, reporter):
|
||||||
# TODO sys.stderr is captured by default ?!??!
|
self.reporter = reporter
|
||||||
self.tw = py.io.TerminalWriter(sys.stderr)
|
super(TerminalReporterHandler, self).__init__()
|
||||||
super(TerminalWriterHandler, self).__init__()
|
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
self.tw.write(self.format(record))
|
# FIXME: I don't get any output with the reporter obj
|
||||||
|
# self.reporter.write(self.format(record))
|
||||||
|
print(self.format(record))
|
||||||
|
|
||||||
|
|
||||||
class LogCaptureFixture(object):
|
class LogCaptureFixture(object):
|
||||||
|
@ -264,7 +266,6 @@ class LoggingPlugin(object):
|
||||||
get_option_ini(config, 'log_format'),
|
get_option_ini(config, 'log_format'),
|
||||||
get_option_ini(config, 'log_date_format'))
|
get_option_ini(config, 'log_date_format'))
|
||||||
|
|
||||||
|
|
||||||
log_cli_format = get_option_ini(
|
log_cli_format = get_option_ini(
|
||||||
config, 'log_cli_format', 'log_format')
|
config, 'log_cli_format', 'log_format')
|
||||||
log_cli_date_format = get_option_ini(
|
log_cli_date_format = get_option_ini(
|
||||||
|
@ -273,6 +274,8 @@ class LoggingPlugin(object):
|
||||||
log_cli_format,
|
log_cli_format,
|
||||||
datefmt=log_cli_date_format)
|
datefmt=log_cli_date_format)
|
||||||
|
|
||||||
|
self.reporter = _pytest.config.create_terminal_writer(config, sys.stdout)
|
||||||
|
|
||||||
log_file = get_option_ini(config, 'log_file')
|
log_file = get_option_ini(config, 'log_file')
|
||||||
if log_file:
|
if log_file:
|
||||||
self.log_file_level = get_actual_log_level(
|
self.log_file_level = get_actual_log_level(
|
||||||
|
@ -296,6 +299,10 @@ class LoggingPlugin(object):
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def _runtest_for(self, item, when):
|
def _runtest_for(self, item, when):
|
||||||
"""Implements the internals of pytest_runtest_xxx() hook."""
|
"""Implements the internals of pytest_runtest_xxx() hook."""
|
||||||
|
if self.capture_log != 'on-failure':
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
|
||||||
with catching_logs(LogCaptureHandler(),
|
with catching_logs(LogCaptureHandler(),
|
||||||
formatter=self.formatter) as log_handler:
|
formatter=self.formatter) as log_handler:
|
||||||
item.catch_log_handler = log_handler
|
item.catch_log_handler = log_handler
|
||||||
|
@ -328,9 +335,8 @@ class LoggingPlugin(object):
|
||||||
def pytest_runtestloop(self, session):
|
def pytest_runtestloop(self, session):
|
||||||
"""Runs all collected test items."""
|
"""Runs all collected test items."""
|
||||||
|
|
||||||
# TODO what should happen at the end of the tests?
|
|
||||||
if self.capture_log == 'live':
|
if self.capture_log == 'live':
|
||||||
with catching_logs(TerminalWriterHandler(),
|
with catching_logs(TerminalReporterHandler(self.reporter),
|
||||||
formatter=self.log_cli_formatter,
|
formatter=self.log_cli_formatter,
|
||||||
level=self.log_cli_level):
|
level=self.log_cli_level):
|
||||||
if self.log_file_handler is not None:
|
if self.log_file_handler is not None:
|
||||||
|
|
Loading…
Reference in New Issue