Bug 1638981 - enable mach reftests to run with Python 3. draft
authorBob Clary <bclary@bclary.com>
Fri, 22 May 2020 09:44:03 -0700
changeset 2913089 08c8abb468f14181322c5c8f4018ef1175db69e6
parent 2913088 f70093c144f5dc9353f60d9fe734eb8aefea87d8
child 2913090 6f476ec27ad67ab0eefd696a98da8576d8da402e
push id542231
push userbclary@mozilla.com
push dateSun, 24 May 2020 06:08:15 +0000
treeherdertry@5bd349510b42 [default view] [failures only]
bugs1638981
milestone78.0a1
Bug 1638981 - enable mach reftests to run with Python 3.
layout/tools/reftest/reftestcommandline.py
layout/tools/reftest/remotereftest.py
layout/tools/reftest/runreftest.py
mach
--- a/layout/tools/reftest/reftestcommandline.py
+++ b/layout/tools/reftest/reftestcommandline.py
@@ -1,18 +1,19 @@
 from __future__ import absolute_import, print_function
 
 import argparse
 import os
 import sys
 from collections import OrderedDict
-from urlparse import urlparse
 import mozinfo
 import mozlog
 
+from six.moves.urllib.parse import urlparse
+
 here = os.path.abspath(os.path.dirname(__file__))
 
 
 class ReftestArgumentsParser(argparse.ArgumentParser):
     def __init__(self, **kwargs):
         super(ReftestArgumentsParser, self).__init__(**kwargs)
 
         # Try to import a MozbuildObject. Success indicates that we are
--- a/layout/tools/reftest/remotereftest.py
+++ b/layout/tools/reftest/remotereftest.py
@@ -8,19 +8,20 @@ import os
 import posixpath
 import psutil
 import signal
 import subprocess
 import sys
 import tempfile
 import time
 import traceback
-import urllib2
 from contextlib import closing
 
+from six.moves.urllib_request import urlopen
+
 from mozdevice import ADBDevice, ADBTimeoutError
 from remoteautomation import RemoteAutomation, fennecLogcatFilters
 
 from output import OutputHandler
 from runreftest import RefTest, ReftestResolver, build_obj
 import reftestcommandline
 
 # We need to know our current directory so that we can serve our test files from it.
@@ -136,17 +137,17 @@ class ReftestServer:
             self.log.error("TEST-UNEXPECTED-FAIL | remotereftests.py | "
                            "Timed out while waiting for server startup.")
             self.stop()
             return 1
 
     def stop(self):
         if hasattr(self, '_process'):
             try:
-                with closing(urllib2.urlopen(self.shutdownURL)) as c:
+                with closing(urlopen(self.shutdownURL)) as c:
                     c.read()
 
                 rtncode = self._process.poll()
                 if (rtncode is None):
                     self._process.terminate()
             except Exception:
                 self.log.info("Failed to shutdown server at %s" % self.shutdownURL)
                 traceback.print_exc()
--- a/layout/tools/reftest/runreftest.py
+++ b/layout/tools/reftest/runreftest.py
@@ -45,18 +45,22 @@ from mozscreenshot import printstatus, d
 from six import reraise, string_types
 from six.moves import range
 
 try:
     from marionette_driver.addons import Addons
     from marionette_harness import Marionette
 except ImportError as e:  # noqa
     # Defer ImportError until attempt to use Marionette
+    # Python 3 deletes the exception once the except block
+    # is exited. Save a version to raise later.
+    e_save = ImportError(str(e))
+
     def reraise_(*args, **kwargs):
-        raise(e)  # noqa
+        raise(e_save)  # noqa
     Marionette = reraise_
 
 from output import OutputHandler, ReftestFormatter
 import reftestcommandline
 
 here = os.path.abspath(os.path.dirname(__file__))
 
 try:
@@ -229,17 +233,17 @@ class ReftestResolver(object):
         suite = options.suite
         manifests = {}
         for testPath in tests:
             for manifest, filter_str in self.findManifest(suite, testPath):
                 if manifest not in manifests:
                     manifests[manifest] = set()
                 manifests[manifest].add(filter_str)
         manifests_by_url = {}
-        for key in manifests.iterkeys():
+        for key in manifests.keys():
             id = os.path.relpath(os.path.abspath(os.path.dirname(key)), options.topsrcdir)
             id = id.replace(os.sep, posixpath.sep)
             if None in manifests[key]:
                 manifests[key] = (None, id)
             else:
                 manifests[key] = ("|".join(list(manifests[key])), id)
             url = self.manifestURL(options, key)
             manifests_by_url[url] = manifests[key]
--- a/mach
+++ b/mach
@@ -35,17 +35,16 @@ py2commands="
     pastebin
     power
     prettier-format
     puppeteer-test
     python
     python-test
     raptor
     raptor-test
-    reftest
     release
     rusttests
     static-analysis
     talos-test
     taskcluster-build-image
     taskcluster-load-image
     taskgraph
     telemetry-tests-client