Bug 1472199 - Set the root directory for Python unit tests to topsrcdir; r?ahal draft
authorDave Hunt <dhunt@mozilla.com>
Mon, 02 Jul 2018 11:22:37 +0100
changeset 814490 2507d31eb41ec912a3706ea09adad35575fdf719
parent 814489 8bbd3447861fc4bdd810e646855a35ea1552d7c4
push id115231
push userbmo:dave.hunt@gmail.com
push dateThu, 05 Jul 2018 13:44:38 +0000
reviewersahal
bugs1472199
milestone63.0a1
Bug 1472199 - Set the root directory for Python unit tests to topsrcdir; r?ahal MozReview-Commit-ID: 4k4CTwzAbli
config/mozunit/mozunit/mozunit.py
--- a/config/mozunit/mozunit/mozunit.py
+++ b/config/mozunit/mozunit/mozunit.py
@@ -9,16 +9,26 @@ import sys
 import unittest
 from unittest import TextTestRunner as _TestRunner, TestResult as _TestResult
 
 import pytest
 import six
 
 here = os.path.abspath(os.path.dirname(__file__))
 
+try:
+    # buildconfig doesn't yet support Python 3, so we can use pathlib to
+    # resolve the topsrcdir relative to our current location.
+    from pathlib import Path
+    topsrcdir = Path(here).parents[2]
+except ImportError:
+    from mozbuild.base import MozbuildObject
+    build = MozbuildObject.from_environment(cwd=here)
+    topsrcdir = build.topsrcdir
+
 StringIO = six.StringIO
 
 '''Helper to make python unit tests report the way that the Mozilla
 unit test infrastructure expects tests to report.
 
 Usage:
 
 import mozunit
@@ -229,15 +239,16 @@ def main(*args, **kwargs):
         unittest.main(testRunner=MozTestRunner(), *args, **kwargs)
     else:
         args = list(args)
         if os.environ.get('MACH_STDOUT_ISATTY') and not any(a.startswith('--color') for a in args):
             args.append('--color=yes')
 
         module = __import__('__main__')
         args.extend([
+            '--rootdir', topsrcdir,
             '-c', os.path.join(here, 'pytest.ini'),
             '-vv',
             '-p', 'mozlog.pytest_mozlog.plugin',
             '-p', 'no:cacheprovider',
             module.__file__,
         ])
         sys.exit(pytest.main(args))