Bug 1539449 - [marionette] Suppress Gecko output in test_crash.py to prevent mozharness failure, r=whimboo
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 24 May 2019 22:17:24 +0000
changeset 475739 cfc637a0af121a114c49a77931bc20d9dc9ff21d
parent 475738 f9397b497e497a3ef8fd43b7cd10633e6d0a6eeb
child 475740 ab74270b2ce72415a756b961fe78d54ab2432e26
push id86447
push userahalberstadt@mozilla.com
push dateMon, 27 May 2019 15:03:33 +0000
treeherderautoland@cfc637a0af12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhimboo
bugs1539449
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1539449 - [marionette] Suppress Gecko output in test_crash.py to prevent mozharness failure, r=whimboo Differential Revision: https://phabricator.services.mozilla.com/D32169
testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
@@ -1,19 +1,21 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
 
 import glob
 import os
 import platform
 import shutil
+import sys
 import unittest
+from io import StringIO
 
 from marionette_driver import Wait
 from marionette_driver.errors import (
     InvalidSessionIdException,
     NoSuchWindowException,
     TimeoutException
 )
 
@@ -94,16 +96,35 @@ class BaseCrashTestCase(MarionetteTestCa
         try:
             self.marionette.navigate("about:crash{}".format("parent" if parent else "content"))
         finally:
             self.marionette.client.socket_timeout = socket_timeout
 
 
 class TestCrash(BaseCrashTestCase):
 
+    def setUp(self):
+        if os.environ.get('MOZ_AUTOMATION'):
+            # Capture stdout, otherwise the Gecko output causes mozharness to fail
+            # the task due to "A content process has crashed" appearing in the log.
+            # To view stdout for debugging, use `print(self.new_out.getvalue())`
+            print("Suppressing GECKO output. To view, add `print(self.new_out.getvalue())` "
+                  "to the end of this test.")
+            self.new_out, self.new_err = StringIO(), StringIO()
+            self.old_out, self.old_err = sys.stdout, sys.stderr
+            sys.stdout, sys.stderr = self.new_out, self.new_err
+
+        super(TestCrash, self).setUp()
+
+    def tearDown(self):
+        super(TestCrash, self).tearDown()
+
+        if os.environ.get('MOZ_AUTOMATION'):
+            sys.stdout, sys.stderr = self.old_out, self.old_err
+
     @unittest.skipIf(platform.machine() == "ARM64" and platform.system() == "Windows",
                      "Bug 1540784 - crashreporter related issues on Windows 10 aarch64. ")
     def test_crash_chrome_process(self):
         self.assertRaisesRegexp(IOError, "Process crashed",
                                 self.crash, parent=True)
 
         # A crash results in a non zero exit code
         self.assertNotIn(self.marionette.instance.runner.returncode, (None, 0))