We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ee96214 + 538efef commit 49f36bbCopy full SHA for 49f36bb
changelog/4988.bugfix.rst
@@ -0,0 +1 @@
1
+Close logging's file handler explicitly when the session finishes.
src/_pytest/logging.py
@@ -577,8 +577,15 @@ def pytest_sessionfinish(self):
577
if self.log_cli_handler:
578
self.log_cli_handler.set_when("sessionfinish")
579
if self.log_file_handler is not None:
580
- with catching_logs(self.log_file_handler, level=self.log_file_level):
581
- yield
+ try:
+ with catching_logs(
582
+ self.log_file_handler, level=self.log_file_level
583
+ ):
584
+ yield
585
+ finally:
586
+ # Close the FileHandler explicitly.
587
+ # (logging.shutdown might have lost the weakref?!)
588
+ self.log_file_handler.close()
589
else:
590
yield
591
0 commit comments