https://github.com/da-viper created 
https://github.com/llvm/llvm-project/pull/177970

Python's internal stderr may differ from sys.stderr. 
When Python writes errors, it uses its internal stderr rather than the 
overwritten sys.stderr.
This may not be the same file/handle

Fix the test to explicitly write to the specified stderr.

>From 737a6392c311aaed866108cd03dd8dbbef38e60e Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <[email protected]>
Date: Mon, 26 Jan 2026 14:36:34 +0000
Subject: [PATCH] [lldb] Fix Python stderr redirection in test

Python's internal stderr may differ from sys.stderr. When Python writes
errors, it uses its internal stderr rather than the overwritten sys.stderr.

Fix the test to explicitly write to the specified stderr.
---
 lldb/test/API/python_api/file_handle/TestFileHandle.py | 10 ++++++++--
 lldb/test/Shell/ScriptInterpreter/Python/io.test       |  9 +++++----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/lldb/test/API/python_api/file_handle/TestFileHandle.py 
b/lldb/test/API/python_api/file_handle/TestFileHandle.py
index 70720e3f0fa91..eba758f5a5d28 100644
--- a/lldb/test/API/python_api/file_handle/TestFileHandle.py
+++ b/lldb/test/API/python_api/file_handle/TestFileHandle.py
@@ -684,7 +684,13 @@ def test_stdout_file_interactive(self):
         """Ensure when we read stdin from a file, outputs from python goes to 
the right I/O stream."""
         with open(self.in_filename, "w") as f:
             f.write(
-                "script --language python --\nvalue = 250 + 
5\nprint(value)\nprint(vel)"
+                """script --language python --
+import sys
+variable = 250 + 5
+print(variable)
+print("wrote to", "stderr", file=sys.stderr)
+quit
+"""
             )
 
         with open(self.out_filename, "w") as outf, open(
@@ -712,7 +718,7 @@ def test_stdout_file_interactive(self):
             )
             self.dbg.GetOutputFile().Flush()
         expected_out_text = "255"
-        expected_err_text = "NameError"
+        expected_err_text = "wrote to stderr"
         # check stdout
         with open(self.out_filename, "r") as f:
             out_text = f.read()
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/io.test 
b/lldb/test/Shell/ScriptInterpreter/Python/io.test
index 1a3ff8dcd4258..f4303d4bcdf49 100644
--- a/lldb/test/Shell/ScriptInterpreter/Python/io.test
+++ b/lldb/test/Shell/ScriptInterpreter/Python/io.test
@@ -5,10 +5,11 @@
 # RUN: cat %t.stdout | FileCheck %s --check-prefix STDOUT
 # RUN: cat %t.stderr | FileCheck %s --check-prefix STDERR
 script
-variable = 300
+import sys
+variable = 250 + 5
 print(variable)
-print(not_value)
+print("wrote to", "stderr", file=sys.stderr)
 quit
 
-# STDOUT: 300
-# STDERR: NameError{{.*}}is not defined
+# STDOUT: 255
+# STDERR: wrote to stderr

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to