[Python-checkins] cpython: Issue 23314: SuppressCrashReports now disables CRT assertions
steve.dower
python-checkins at python.org
Mon Feb 23 20:45:25 CET 2015
https://hg.python.org/cpython/rev/bb67b810aac1
changeset: 94735:bb67b810aac1
user: Steve Dower <steve.dower at microsoft.com>
date: Mon Feb 23 07:56:13 2015 -0800
summary:
Issue 23314: SuppressCrashReports now disables CRT assertions
SuppressCrashReports should be used in test subprocesses that test invalid conditions.
files:
Lib/test/support/__init__.py | 27 ++++++++++++++++++++
Lib/test/tf_inherit_check.py | 32 ++++++++++++-----------
2 files changed, 44 insertions(+), 15 deletions(-)
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2151,6 +2151,7 @@
disable the creation of coredump file.
"""
old_value = None
+ old_modes = None
def __enter__(self):
"""On Windows, disable Windows Error Reporting dialogs using
@@ -2168,6 +2169,26 @@
SEM_NOGPFAULTERRORBOX = 0x02
self.old_value = self._k32.SetErrorMode(SEM_NOGPFAULTERRORBOX)
self._k32.SetErrorMode(self.old_value | SEM_NOGPFAULTERRORBOX)
+
+ # Suppress assert dialogs in debug builds
+ # (see http://bugs.python.org/issue23314)
+ try:
+ import msvcrt
+ msvcrt.CrtSetReportMode
+ except (AttributeError, ImportError):
+ # no msvcrt or a release build
+ pass
+ else:
+ self.old_modes = {}
+ for report_type in [msvcrt.CRT_WARN,
+ msvcrt.CRT_ERROR,
+ msvcrt.CRT_ASSERT]:
+ old_mode = msvcrt.CrtSetReportMode(report_type,
+ msvcrt.CRTDBG_MODE_FILE)
+ old_file = msvcrt.CrtSetReportFile(report_type,
+ msvcrt.CRTDBG_FILE_STDERR)
+ self.old_modes[report_type] = old_mode, old_file
+
else:
if resource is not None:
try:
@@ -2199,6 +2220,12 @@
if sys.platform.startswith('win'):
self._k32.SetErrorMode(self.old_value)
+
+ if self.old_modes:
+ import msvcrt
+ for report_type, (old_mode, old_file) in self.old_modes.items():
+ msvcrt.CrtSetReportMode(report_type, old_mode)
+ msvcrt.CrtSetReportFile(report_type, old_file)
else:
if resource is not None:
try:
diff --git a/Lib/test/tf_inherit_check.py b/Lib/test/tf_inherit_check.py
--- a/Lib/test/tf_inherit_check.py
+++ b/Lib/test/tf_inherit_check.py
@@ -4,22 +4,24 @@
import sys
import os
+from test.support import SuppressCrashReport
-verbose = (sys.argv[1] == 'v')
-try:
- fd = int(sys.argv[2])
+with SuppressCrashReport():
+ verbose = (sys.argv[1] == 'v')
+ try:
+ fd = int(sys.argv[2])
- try:
- os.write(fd, b"blat")
- except OSError:
- # Success -- could not write to fd.
- sys.exit(0)
- else:
+ try:
+ os.write(fd, b"blat")
+ except OSError:
+ # Success -- could not write to fd.
+ sys.exit(0)
+ else:
+ if verbose:
+ sys.stderr.write("fd %d is open in child" % fd)
+ sys.exit(1)
+
+ except Exception:
if verbose:
- sys.stderr.write("fd %d is open in child" % fd)
+ raise
sys.exit(1)
-
-except Exception:
- if verbose:
- raise
- sys.exit(1)
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list