Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --print-logs option #65

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions pytest_catchlog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import logging
import sys
from contextlib import closing, contextmanager
from contextlib import contextmanager

import pytest
import py

from pytest_catchlog.common import catching_logs

# Let the fixtures be discoverable by pytest.
from pytest_catchlog.fixture import caplog, capturelog
from pytest_catchlog.fixture import caplog, capturelog # noqa


DEFAULT_LOG_FORMAT = '%(filename)-25s %(lineno)4d %(levelname)-8s %(message)s'
Expand All @@ -34,24 +34,32 @@ def get_option_ini(config, name):
def pytest_addoption(parser):
"""Add options to control log capturing."""

group = parser.getgroup('catchlog', 'Log catching')
add_option_ini(parser,
add_option_ini(
parser,
'--no-print-logs',
dest='log_print', action='store_const', const=False, default=True,
help='disable printing caught logs on failed tests.'
)
add_option_ini(
parser,
'--print-logs',
dest='log_print', action='store_const', const=True, default=True,
help='enable printing caught logs on failed tests (default).'
)
add_option_ini(
parser,
'--log-level',
dest='log_level', default=None,
help='logging level used by the logging module'
)
add_option_ini(parser,
add_option_ini(
parser,
'--log-format',
dest='log_format', default=DEFAULT_LOG_FORMAT,
help='log format as used by the logging module.'
)
add_option_ini(parser,
add_option_ini(
parser,
'--log-date-format',
dest='log_date_format', default=DEFAULT_LOG_DATE_FORMAT,
help='log date format as used by the logging module.'
Expand Down Expand Up @@ -100,7 +108,6 @@ def pytest_addoption(parser):
)



def get_actual_log_level(config, setting_name):
"""Return the actual logging level."""
log_level = get_option_ini(config, setting_name)
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ universal = 1

[sdist]
formats = zip

[flake8]
max-line-length = 100