cpython: bb67b810aac1 (original) (raw)
Mercurial > cpython
changeset 94735:bb67b810aac1
Issue 23314: SuppressCrashReports now disables CRT assertions SuppressCrashReports should be used in test subprocesses that test invalid conditions.
Steve Dower steve.dower@microsoft.com | |
---|---|
date | Mon, 23 Feb 2015 07:56:13 -0800 |
parents | 516d3773ecb2 |
children | 3673cc0c1b8f |
files | Lib/test/support/__init__.py Lib/test/tf_inherit_check.py |
diffstat | 2 files changed, 44 insertions(+), 15 deletions(-)[+] [-] Lib/test/support/__init__.py 27 Lib/test/tf_inherit_check.py 32 |
line wrap: on
line diff
--- a/Lib/test/support/init.py +++ b/Lib/test/support/init.py @@ -2151,6 +2151,7 @@ class SuppressCrashReport: disable the creation of coredump file. """ old_value = None
def enter(self): """On Windows, disable Windows Error Reporting dialogs using @@ -2168,6 +2169,26 @@ class SuppressCrashReport: 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[](#l1.16)
# (see http://bugs.python.org/issue23314)[](#l1.17)
try:[](#l1.18)
import msvcrt[](#l1.19)
msvcrt.CrtSetReportMode[](#l1.20)
except (AttributeError, ImportError):[](#l1.21)
# no msvcrt or a release build[](#l1.22)
pass[](#l1.23)
else:[](#l1.24)
self.old_modes = {}[](#l1.25)
for report_type in [msvcrt.CRT_WARN,[](#l1.26)
msvcrt.CRT_ERROR,[](#l1.27)
msvcrt.CRT_ASSERT]:[](#l1.28)
old_mode = msvcrt.CrtSetReportMode(report_type,[](#l1.29)
msvcrt.CRTDBG_MODE_FILE)[](#l1.30)
old_file = msvcrt.CrtSetReportFile(report_type,[](#l1.31)
msvcrt.CRTDBG_FILE_STDERR)[](#l1.32)
self.old_modes[report_type] = old_mode, old_file[](#l1.33)
+ else: if resource is not None: try: @@ -2199,6 +2220,12 @@ class SuppressCrashReport: if sys.platform.startswith('win'): self._k32.SetErrorMode(self.old_value) +
if self.old_modes:[](#l1.43)
import msvcrt[](#l1.44)
for report_type, (old_mode, old_file) in self.old_modes.items():[](#l1.45)
msvcrt.CrtSetReportMode(report_type, old_mode)[](#l1.46)
msvcrt.CrtSetReportFile(report_type, old_file)[](#l1.47) else:[](#l1.48) if resource is not None:[](#l1.49) try:[](#l1.50)
--- 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:
- +with SuppressCrashReport():
os.write(fd, b"blat")[](#l2.16)
- except OSError:
# Success -- could not write to fd.[](#l2.18)
sys.exit(0)[](#l2.19)
- else:
fd = int(sys.argv[2])[](#l2.21)
try:[](#l2.23)
os.write(fd, b"blat")[](#l2.24)
except OSError:[](#l2.25)
# Success -- could not write to fd.[](#l2.26)
sys.exit(0)[](#l2.27)
else:[](#l2.28)
if verbose:[](#l2.29)
sys.stderr.write("fd %d is open in child" % fd)[](#l2.30)
sys.exit(1)[](#l2.31)
sys.stderr.write("fd %d is open in child" % fd)[](#l2.35)
raise[](#l2.36) sys.exit(1)[](#l2.37)