Skip to content

[libclang/python] Properly report errors when test fails #142371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions clang/bindings/python/tests/cindex/test_cdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading