Author: Jannick Kremer Date: 2025-06-02T16:14:39+02:00 New Revision: c5da47108ab77358f5fa5d43fd4d8344086c831f
URL: https://github.com/llvm/llvm-project/commit/c5da47108ab77358f5fa5d43fd4d8344086c831f DIFF: https://github.com/llvm/llvm-project/commit/c5da47108ab77358f5fa5d43fd4d8344086c831f.diff LOG: [libclang/python] Properly report errors when test fails (#142371) test_cdb.py's test_create_fail captures stderr to suppress output but did not release it in case the test fails. Added: Modified: clang/bindings/python/tests/cindex/test_cdb.py Removed: ################################################################################ diff --git a/clang/bindings/python/tests/cindex/test_cdb.py b/clang/bindings/python/tests/cindex/test_cdb.py index 757a14fbaef2c..5abe56f0d65f8 100644 --- a/clang/bindings/python/tests/cindex/test_cdb.py +++ b/clang/bindings/python/tests/cindex/test_cdb.py @@ -21,13 +21,16 @@ def test_create_fail(self): # clang_CompilationDatabase_fromDirectory calls fprintf(stderr, ...) # Suppress its output. - stderr = os.dup(2) - with open(os.devnull, "wb") as null: - os.dup2(null.fileno(), 2) - with self.assertRaises(CompilationDatabaseError) as cm: - CompilationDatabase.fromDirectory(path) - os.dup2(stderr, 2) - os.close(stderr) + try: + stderr = os.dup(2) + with open(os.devnull, "wb") as null: + os.dup2(null.fileno(), 2) + with self.assertRaises(CompilationDatabaseError) as cm: + CompilationDatabase.fromDirectory(path) + # Ensures that stderr is reset even if the above code crashes + finally: + os.dup2(stderr, 2) + os.close(stderr) e = cm.exception self.assertEqual(e.cdb_error, CompilationDatabaseError.ERROR_CANNOTLOADDATABASE) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits