Skip to content

Commit 2f3ef3c

Browse files
Copilotbittner
andcommitted
Fix Windows permission errors by closing logging handlers before cleanup
Co-authored-by: bittner <[email protected]>
1 parent 13f305d commit 2f3ef3c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cli_test_helpers/decorators.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ def __enter__(self):
3333

3434
def __exit__(self, exc_type, exc_val, exc_tb):
3535
"""Restore logging handlers after exiting the context."""
36+
# Close and remove any handlers that were added during the context
3637
if hasattr(self, "_old_handlers"):
38+
for handler in logging.root.handlers[:]:
39+
# Close handlers that weren't in the original list
40+
if handler not in self._old_handlers:
41+
handler.close()
42+
logging.root.handlers.remove(handler)
43+
# Restore the original handlers
3744
logging.root.handlers[:] = self._old_handlers
3845
# Call parent __exit__ if it exists (for cooperative inheritance)
3946
if hasattr(super(), "__exit__"):

0 commit comments

Comments
 (0)