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
--- 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))