From 3a4011585f67981595d6a2eb8ca3de78bbe2f251 Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Fri, 15 Sep 2017 13:38:49 +0200 Subject: [PATCH] catching_logs: Remove usage of 'closing' ctx manager The 'closing' context manager is only needed for the log_file_handler. --- _pytest/logging.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/_pytest/logging.py b/_pytest/logging.py index 77ae04424..e9b143369 100644 --- a/_pytest/logging.py +++ b/_pytest/logging.py @@ -127,11 +127,9 @@ def catching_logs(handler, formatter=None, handler.setFormatter(formatter) handler.setLevel(level) - with closing(handler): - with logging_using_handler(handler, logger): - with logging_at_level(min(handler.level, logger.level), logger): - - yield handler + with logging_using_handler(handler, logger): + with logging_at_level(min(handler.level, logger.level), logger): + yield handler class LogCaptureHandler(logging.StreamHandler): @@ -421,8 +419,9 @@ class LoggingPlugin(object): """Runs all collected test items.""" with self.live_logs: if self.log_file_handler is not None: - with catching_logs(self.log_file_handler, - level=self.log_file_level): - yield # run all the tests + with closing(self.log_file_handler): + with catching_logs(self.log_file_handler, + level=self.log_file_level): + yield # run all the tests else: yield # run all the tests