From 3862b0b28d1dac1d9ea398fc6155ed5e6de5498c Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Wed, 13 Dec 2017 21:05:32 +0100 Subject: [PATCH] Remove logger parameter from catching_logs The logger parameter of catching_logs is not used anywhere. The main motivation for removing the logger parameter is that it removes the logger = logger or logging.getLogger(logger) line. IMO there are too many occurences of the string 'logg' ;) --- _pytest/logging.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/_pytest/logging.py b/_pytest/logging.py index b29f48503..9e82e801d 100644 --- a/_pytest/logging.py +++ b/_pytest/logging.py @@ -79,10 +79,9 @@ def pytest_addoption(parser): @contextmanager -def catching_logs(handler, formatter=None, - level=logging.NOTSET, logger=None): +def catching_logs(handler, formatter=None, level=logging.NOTSET): """Context manager that prepares the whole logging machinery properly.""" - logger = logger or logging.getLogger(logger) + root_logger = logging.getLogger() if formatter is not None: handler.setFormatter(formatter) @@ -90,18 +89,18 @@ def catching_logs(handler, formatter=None, # Adding the same handler twice would confuse logging system. # Just don't do that. - add_new_handler = handler not in logger.handlers + add_new_handler = handler not in root_logger.handlers if add_new_handler: - logger.addHandler(handler) - orig_level = logger.level - logger.setLevel(min(orig_level, level)) + root_logger.addHandler(handler) + orig_level = root_logger.level + root_logger.setLevel(min(orig_level, level)) try: yield handler finally: - logger.setLevel(orig_level) + root_logger.setLevel(orig_level) if add_new_handler: - logger.removeHandler(handler) + root_logger.removeHandler(handler) class LogCaptureHandler(logging.StreamHandler):