From 78f9d78b13423ecfc354579ef00599f68e0f5b88 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Mon, 26 Jan 2026 22:20:55 +0000 Subject: [lldb] Fix Python stderr redirection in test (#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. --- lldb/test/API/python_api/file_handle/TestFileHandle.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lldb/test/API/python_api') diff --git a/lldb/test/API/python_api/file_handle/TestFileHandle.py b/lldb/test/API/python_api/file_handle/TestFileHandle.py index 70720e3f0fa9..eba758f5a5d2 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 @@ class FileHandleTestCase(lldbtest.TestBase): """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 @@ class FileHandleTestCase(lldbtest.TestBase): ) 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() -- cgit v1.2.3