diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-06-12 23:09:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-12 23:09:04 (GMT) |
commit | 95f61c8b1619e736bd5e29a0da0183234634b6e8 (patch) | |
tree | 6d70a71d5e9538ab70d9039eabf64315409e939d /Lib/test/libregrtest/utils.py | |
parent | 913fa1c8245d1cde6edb4254f4fb965cc91786ef (diff) | |
download | cpython-95f61c8b1619e736bd5e29a0da0183234634b6e8.zip cpython-95f61c8b1619e736bd5e29a0da0183234634b6e8.tar.gz cpython-95f61c8b1619e736bd5e29a0da0183234634b6e8.tar.bz2 |
bpo-37069: regrtest uses sys.unraisablehook (GH-13759)
regrtest now uses sys.unraisablehook() to mark a test as "environment
altered" (ENV_CHANGED) if it emits an "unraisable exception".
Moreover, regrtest logs a warning in this case.
Use "python3 -m test --fail-env-changed" to catch unraisable
exceptions in tests.
Diffstat (limited to 'Lib/test/libregrtest/utils.py')
-rw-r--r-- | Lib/test/libregrtest/utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index fb9971a..2691a2c 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -2,6 +2,7 @@ import math import os.path import sys import textwrap +from test import support def format_duration(seconds): @@ -59,3 +60,19 @@ def printlist(x, width=70, indent=4, file=None): def print_warning(msg): print(f"Warning -- {msg}", file=sys.stderr, flush=True) + + +orig_unraisablehook = None + + +def regrtest_unraisable_hook(unraisable): + global orig_unraisablehook + support.environment_altered = True + print_warning("Unraisable exception") + orig_unraisablehook(unraisable) + + +def setup_unraisable_hook(): + global orig_unraisablehook + orig_unraisablehook = sys.unraisablehook + sys.unraisablehook = regrtest_unraisable_hook |