Skip to content

Commit bd5e3f0

Browse files
committed
logging: move log_file_handler cleanup from sessionend to unconfigure
It is set-up in configure, so match it.
1 parent 43c465c commit bd5e3f0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/_pytest/logging.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,6 @@ def pytest_sessionfinish(self):
678678
with catching_logs(self.log_file_handler, level=self.log_file_level):
679679
yield
680680

681-
# Close the FileHandler explicitly.
682-
# (logging.shutdown might have lost the weakref?!)
683-
self.log_file_handler.close()
684-
685681
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
686682
def pytest_sessionstart(self):
687683
self.log_cli_handler.set_when("sessionstart")
@@ -706,6 +702,12 @@ def pytest_runtestloop(self, session):
706702
with catching_logs(self.log_file_handler, level=self.log_file_level):
707703
yield # run all the tests
708704

705+
@pytest.hookimpl
706+
def pytest_unconfigure(self):
707+
# Close the FileHandler explicitly.
708+
# (logging.shutdown might have lost the weakref?!)
709+
self.log_file_handler.close()
710+
709711

710712
class _LiveLoggingStreamHandler(logging.StreamHandler):
711713
"""

0 commit comments

Comments
 (0)