]> granicus.if.org Git - python/commitdiff
[3.5] bpo-30107: don't dump core on expected test_io crash (#1235) (#1344)
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 28 Apr 2017 14:59:44 +0000 (16:59 +0200)
committerGitHub <noreply@github.com>
Fri, 28 Apr 2017 14:59:44 +0000 (16:59 +0200)
* bpo-30107: Make SuppressCrashReport quiet on macOS (#1279) (#1335)

On macOS, SuppressCrashReport now redirects /usr/bin/defaults command
stderr into a pipe to not pollute stderr. It fixes a
test_io.test_daemon_threads_shutdown_stderr_deadlock() failure when
the CrashReporter domain doesn't exists. Message logged into stderr:

2017-04-24 16:57:21.432 defaults[41046:2462851]
The domain/default pair of (com.apple.CrashReporter, DialogType) does not exist
(cherry picked from commit d819ad9832292d854e9710493ecdf959b69802e3)

* bpo-30107: don't dump core on expected test_io crash (#1235)

test_io has two unit tests which trigger a deadlock:

* test_daemon_threads_shutdown_stdout_deadlock()
* test_daemon_threads_shutdown_stderr_deadlock()

These tests call Py_FatalError() if the expected bug is triggered
which calls abort(). Use test.support.SuppressCrashReport to prevent
the creation on a core dump, to fix the warning:

Warning -- files was modified by test_io
  Before: []
  After:  ['python.core']

Lib/test/support/__init__.py
Lib/test/test_io.py

index d0d126a3a033a507862bfbf7419921e5df3b5eee..a5aba3114370ee80a5c2f0949f2b20a7634a9a1f 100644 (file)
@@ -2337,6 +2337,7 @@ class SuppressCrashReport:
                                        (0, self.old_value[1]))
                 except (ValueError, OSError):
                     pass
+
             if sys.platform == 'darwin':
                 # Check if the 'Crash Reporter' on OSX was configured
                 # in 'Developer' mode and warn that it will get triggered
@@ -2344,10 +2345,14 @@ class SuppressCrashReport:
                 #
                 # This assumes that this context manager is used in tests
                 # that might trigger the next manager.
-                value = subprocess.Popen(['/usr/bin/defaults', 'read',
-                        'com.apple.CrashReporter', 'DialogType'],
-                        stdout=subprocess.PIPE).communicate()[0]
-                if value.strip() == b'developer':
+                cmd = ['/usr/bin/defaults', 'read',
+                       'com.apple.CrashReporter', 'DialogType']
+                proc = subprocess.Popen(cmd,
+                                        stdout=subprocess.PIPE,
+                                        stderr=subprocess.PIPE)
+                with proc:
+                    stdout = proc.communicate()[0]
+                if stdout.strip() == b'developer':
                     print("this test triggers the Crash Reporter, "
                           "that is intentional", end='', flush=True)
 
index b8937c5a183adfe7e9e93fa5f69d1146169cedb4..8b4892b2e56b875f02b0b6fb94a7388b802a421b 100644 (file)
@@ -3688,6 +3688,7 @@ class CMiscIOTest(MiscIOTest):
             import sys
             import time
             import threading
+            from test.support import SuppressCrashReport
 
             file = sys.{stream_name}
 
@@ -3696,6 +3697,10 @@ class CMiscIOTest(MiscIOTest):
                     file.write('.')
                     file.flush()
 
+            crash = SuppressCrashReport()
+            crash.__enter__()
+            # don't call __exit__(): the crash occurs at Python shutdown
+
             thread = threading.Thread(target=run)
             thread.daemon = True
             thread.start()