bpo-38912: regrtest logs unraisable exception into sys.__stderr__ (GH-21718)
regrtest_unraisable_hook() temporarily replaces sys.stderr with
sys.__stderr__ to help to display errors when a test captures stderr.
diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py
index 0368694..71f538f 100644
--- a/Lib/test/libregrtest/utils.py
+++ b/Lib/test/libregrtest/utils.py
@@ -72,7 +72,12 @@
global orig_unraisablehook
support.environment_altered = True
print_warning("Unraisable exception")
- orig_unraisablehook(unraisable)
+ old_stderr = sys.stderr
+ try:
+ sys.stderr = sys.__stderr__
+ orig_unraisablehook(unraisable)
+ finally:
+ sys.stderr = old_stderr
def setup_unraisable_hook():