-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
test_cdb.py's test_create_fail captures stderr to suppress output but did not release it in case the test fails.
This issue has been raised in #142353 (review) |
@llvm/pr-subscribers-clang Author: Jannick Kremer (DeinAlptraum) Changestest_cdb.py's test_create_fail captures stderr to suppress output but did not release it in case the test fails. Full diff: https://github.com/llvm/llvm-project/pull/142371.diff 1 Files Affected:
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)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you reproduced the issue and checked that this fix does what's it supposed to do?
@Endilll (just to be clear: that doesn't fix any issues related to 32bit/64bit mixing, it just ensures this test doesn't swallow all output whenever it fails) |
test_cdb.py's test_create_fail captures stderr to suppress output but did not release it in case the test fails.
test_cdb.py's test_create_fail captures stderr to suppress output but did not release it in case the test fails.
test_cdb.py's test_create_fail captures stderr to suppress output but did not release it in case the test fails.