From bd5e3f042d9b38bc4b37bd4bbd477fcf76a87383 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 17 May 2020 14:58:04 +0300 Subject: [PATCH] logging: move log_file_handler cleanup from sessionend to unconfigure It is set-up in configure, so match it. --- src/_pytest/logging.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index eca5c240b..39523d0a3 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -678,10 +678,6 @@ class LoggingPlugin: with catching_logs(self.log_file_handler, level=self.log_file_level): yield - # Close the FileHandler explicitly. - # (logging.shutdown might have lost the weakref?!) - self.log_file_handler.close() - @pytest.hookimpl(hookwrapper=True, tryfirst=True) def pytest_sessionstart(self): self.log_cli_handler.set_when("sessionstart") @@ -706,6 +702,12 @@ class LoggingPlugin: with catching_logs(self.log_file_handler, level=self.log_file_level): yield # run all the tests + @pytest.hookimpl + def pytest_unconfigure(self): + # Close the FileHandler explicitly. + # (logging.shutdown might have lost the weakref?!) + self.log_file_handler.close() + class _LiveLoggingStreamHandler(logging.StreamHandler): """