From 8acb66dfd2c8fb19ed9b9cb09f2556be346da1dc Mon Sep 17 00:00:00 2001 From: StillKnotKnown Date: Thu, 5 Feb 2026 20:31:04 +0200 Subject: [PATCH] fix: prevent stdout.close() in tests for OSError EPIPE handler The OSError exception handler for EPIPE errors was calling sys.stdout.close() without checking the AUTO_CLAUDE_TESTS flag, causing CI to fail on test_safe_print_os_error_epipe. This adds the same _IN_TESTS check that the BrokenPipeError handler already has. Fixes CI failure: test-python on test-coverage-improvements branch --- apps/backend/core/io_utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/backend/core/io_utils.py b/apps/backend/core/io_utils.py index 778d2067..62a49e1e 100644 --- a/apps/backend/core/io_utils.py +++ b/apps/backend/core/io_utils.py @@ -68,10 +68,12 @@ def safe_print(message: str, flush: bool = True) -> None: # Handle other pipe-related errors (EPIPE, etc.) if e.errno == 32: # EPIPE - Broken pipe _pipe_broken = True - try: - sys.stdout.close() - except Exception: - pass + # Skip closing stdout during tests to avoid pytest capture issues + if not _IN_TESTS: + try: + sys.stdout.close() + except Exception: + pass logger.debug("Output pipe closed (EPIPE)") else: # Re-raise unexpected OS errors