mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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.
This commit is contained in:
parent
913fa1c824
commit
95f61c8b16
4 changed files with 57 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue