Bug 1335873 - Ignore MozconfigFindException when looking for a mozinfo.json, r?maja_zf draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 15 Feb 2017 16:37:58 -0500
changeset 491142 a00518211f086e72ca724533b13a276bb7d46457
parent 490871 34c6c2f302e7b48e3ad2cec575cbd34d423a9d32
child 491143 45e481fe4caef53472bf56d40c13158dd2eb3c20
push id47332
push userahalberstadt@mozilla.com
push dateWed, 01 Mar 2017 20:43:26 +0000
reviewersmaja_zf
bugs1335873
milestone54.0a1
Bug 1335873 - Ignore MozconfigFindException when looking for a mozinfo.json, r?maja_zf This gets raised when trying to run the marionette-harness python tests without an objdir. It's safe to ignore because mozinfo.json will still be found via the 'dirs' variable which gets passed in from the marionette harness. MozReview-Commit-ID: Ata99evHxbd
testing/mozbase/mozinfo/mozinfo/mozinfo.py
testing/mozbase/mozinfo/tests/test.py
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py
+++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py
@@ -213,24 +213,25 @@ def find_and_update_from_json(*dirs):
                  searched after first looking in the root of the objdir
                  if the current script is being run from a Mozilla objdir.
 
     Returns the full path to mozinfo.json if it was found, or None otherwise.
     """
     # First, see if we're in an objdir
     try:
         from mozbuild.base import MozbuildObject, BuildEnvironmentNotFoundException
+        from mozbuild.mozconfig import MozconfigFindException
         build = MozbuildObject.from_environment()
         json_path = _os.path.join(build.topobjdir, "mozinfo.json")
         if _os.path.isfile(json_path):
             update(json_path)
             return json_path
     except ImportError:
         pass
-    except BuildEnvironmentNotFoundException:
+    except (BuildEnvironmentNotFoundException, MozconfigFindException):
         pass
 
     for d in dirs:
         d = _os.path.abspath(d)
         json_path = _os.path.join(d, "mozinfo.json")
         if _os.path.isfile(json_path):
             update(json_path)
             return json_path
--- a/testing/mozbase/mozinfo/tests/test.py
+++ b/testing/mozbase/mozinfo/tests/test.py
@@ -78,17 +78,23 @@ class TestMozinfo(unittest.TestCase):
         """Test that mozinfo.find_and_update_from_json can
         find mozinfo.json using the mozbuild module."""
         j = os.path.join(self.tempdir, "mozinfo.json")
         with open(j, "w") as f:
             f.write(json.dumps({"foo": "123456"}))
         m = mock.MagicMock()
         # Mock the value of MozbuildObject.from_environment().topobjdir.
         m.MozbuildObject.from_environment.return_value.topobjdir = self.tempdir
-        with mock.patch.dict(sys.modules, {"mozbuild": m, "mozbuild.base": m}):
+
+        mocked_modules = {
+            "mozbuild": m,
+            "mozbuild.base": m,
+            "mozbuild.mozconfig": m,
+        }
+        with mock.patch.dict(sys.modules, mocked_modules):
             self.assertEqual(mozinfo.find_and_update_from_json(), j)
         self.assertEqual(mozinfo.info["foo"], "123456")
 
     def test_output_to_file(self):
         """Test that mozinfo.output_to_file works."""
         path = os.path.join(self.tempdir, "mozinfo.json")
         mozinfo.output_to_file(path)
         self.assertEqual(open(path).read(), json.dumps(mozinfo.info))