pytest-catchlog icon indicating copy to clipboard operation
pytest-catchlog copied to clipboard

Catching logs of pytest-flake8 plugin

Open GergelyKalmar opened this issue 8 years ago • 5 comments

When using the pytest-flake8 plugin the flake logs get catched by pytest-catchlog, making it difficult to see the actual flake error output:

`======== FAILURES ======== _______ FLAKE8-check _______ /home/user/Projects/test/test.py:12:5: F841 local variable 'test' is assigned to but never used

-------- Captured log call -------- flake8.options.manager:: DEBUG: Registered option "Option(-v, --verbose, action=count, default=0, dest=verbose, type=None, callback=None, help=Print more information about what is happening in flake8. This option is repeatable and will increase verbosity each time it is repeated., callback=None, callback_args=None, callback_kwargs=None, metavar=None)". flake8.options.manager:: DEBUG: Registered option "Option(-q, --quiet, action=count, default=0, dest=quiet, type=None, callback=None, help=Report only file names, or nothing. This option is repeatable., callback=None, callback_args=None, callback_kwargs=None, metavar=None)". ... lots of additional flake8 log lines ... flake8.main.application:: INFO: Finished running flake8.main.application:: INFO: Reporting errors flake8.style_guide:: DEBUG: Deciding if "F841" should be reported flake8.style_guide:: DEBUG: The user configured "F841" to be "Selected.Explicitly", "Selected.Implicitly" flake8.style_guide:: DEBUG: "F841" will be "Decision.Selected" flake8.style_guide:: DEBUG: Error(code='F841', filename='/home/user/Projects/test/test.py', line_number=12, column_number=5, text="local variable 'test' is assigned to but never used", physical_line=" test = 'test'\n") is not inline ignored flake8.main.application:: INFO: Found a total of 1 violations and reported 1 ========================`

Is there a possibility to turn off flake8 log catching for an entire pytest session with catchlog or would that be possible to add a command line argument for this?

GergelyKalmar avatar Feb 22 '17 13:02 GergelyKalmar

In case someone is looking for a workaround, there is one. You can disable the 'flake8' logger for the entire session by putting an __init__.py file to the root test path directory with the following content:

from logging import getLogger

getLogger('flake8').propagate = False

GergelyKalmar avatar Mar 10 '17 11:03 GergelyKalmar

Actually I also think that this logger should be disabled by default. It's starting to be headache when dealing with not only checking 'tests', where you can put getLogger('flake8').propagate = False to conftest, but when checking module itself. There should be an option not to propagate some logger names, for example:

    add_option_ini(parser,
               '--log-supress',
               dest='log_supress', default=(''),
               help='supress output from the following logger names, delimited by comma.')
    add_option_ini(parser,
               '--log-only',
               dest='log_only', default=(''),
               help='log output only from the following logger names, delimited by comma.')

vgavro avatar Apr 18 '17 07:04 vgavro

getLogger('flake8').propagate = False helps (but is pretty annoying to have to add like that) i get a HUGE amount of logs using pytest-flake8 like: DEBUG [root] parser.py:346 parsing definition list, current token is tk.NEWLINE ( and i have no idea how to shut them up

revmischa avatar Dec 08 '17 11:12 revmischa

I think maybe a more appropriate default logging setting for flake8 would perhaps be 'WARNING'?

winni2k avatar Dec 16 '17 13:12 winni2k

You can simply add a conftest.py with the following content:

import logging


def pytest_configure(config):
    """Flake8 is very verbose by default. Silence it."""
    logging.getLogger("flake8").setLevel(logging.WARNING)

MartinThoma avatar Mar 19 '20 14:03 MartinThoma