Bug 1472199 - Set the root directory for Python unit tests to topsrcdir; r?ahal
MozReview-Commit-ID: 4k4CTwzAbli
--- 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))