[Lldb-commits] [lldb] [lldb] Fix Python stderr redirection in test (PR #177970)

via lldb-commits lldb-commits at lists.llvm.org
Mon Jan 26 06:53:59 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/177970.diff


2 Files Affected:

- (modified) lldb/test/API/python_api/file_handle/TestFileHandle.py (+8-2) 
- (modified) lldb/test/Shell/ScriptInterpreter/Python/io.test (+5-4) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/177970


More information about the lldb-commits mailing list