Skip to content

Commit

Permalink
Fix some coding-style issues in the logging plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
twmr committed Oct 11, 2017
1 parent 923c6b2 commit 77c326c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions _pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def get_option_ini(config, *names):

def pytest_addoption(parser):
"""Add options to control log capturing."""

group = parser.getgroup('logging')

def add_option_ini(option, dest, default=None, type=None, **kwargs):
Expand Down Expand Up @@ -120,13 +119,11 @@ class LogCaptureHandler(logging.StreamHandler):

def __init__(self):
"""Creates a new log handler."""

logging.StreamHandler.__init__(self, py.io.TextIO())
self.records = []

def emit(self, record):
"""Keep the log records in a list in addition to the log text."""

self.records.append(record)
logging.StreamHandler.emit(self, record)

Expand Down Expand Up @@ -260,17 +257,17 @@ def __init__(self, config):

self.print_logs = get_option_ini(config, 'log_print')
self.formatter = logging.Formatter(
get_option_ini(config, 'log_format'),
get_option_ini(config, 'log_date_format'))
get_option_ini(config, 'log_format'),
get_option_ini(config, 'log_date_format'))

log_cli_handler = logging.StreamHandler(sys.stderr)
log_cli_format = get_option_ini(
config, 'log_cli_format', 'log_format')
log_cli_date_format = get_option_ini(
config, 'log_cli_date_format', 'log_date_format')
log_cli_formatter = logging.Formatter(
log_cli_format,
datefmt=log_cli_date_format)
log_cli_format,
datefmt=log_cli_date_format)
self.log_cli_handler = log_cli_handler # needed for a single unittest
self.live_logs = catching_logs(log_cli_handler,
formatter=log_cli_formatter,
Expand All @@ -288,11 +285,10 @@ def __init__(self, config):
self.log_file_handler = logging.FileHandler(
log_file,
# Each pytest runtests session will write to a clean logfile
mode='w',
)
mode='w')
log_file_formatter = logging.Formatter(
log_file_format,
datefmt=log_file_date_format)
log_file_format,
datefmt=log_file_date_format)
self.log_file_handler.setFormatter(log_file_formatter)
else:
self.log_file_handler = None
Expand Down

0 comments on commit 77c326c

Please sign in to comment.