def run_tests(self, **kwargs): MachCommandBase.activate_virtualenv(self) from pathlib import Path from mozperftest.utils import temporary_env with temporary_env(COVERAGE_RCFILE=str(Path(HERE, ".coveragerc")), RUNNING_TESTS="YES"): self._run_tests(**kwargs)
def activate_browsertime_virtualenv(command_context, *args, **kwargs): r"""Activates virtualenv. This function will also install Pillow and pyssim if needed. It will raise an error in case the install failed. """ MachCommandBase.activate_virtualenv(command_context, *args, **kwargs) # installing Python deps on the fly for dep in ("Pillow==%s" % PILLOW_VERSION, "pyssim==%s" % PYSSIM_VERSION): if _need_install(command_context, dep): command_context.virtualenv_manager._run_pip(["install", dep])
def activate_virtualenv(self, *args, **kwargs): r'''Activates virtualenv. This function will also install Pillow and pyssim if needed. It will raise an error in case the install failed. ''' MachCommandBase.activate_virtualenv(self, *args, **kwargs) # installing Python deps on the fly for dep in ("Pillow==%s" % PILLOW_VERSION, "pyssim==%s" % PYSSIM_VERSION): if self._need_install(dep): self.virtualenv_manager._run_pip(["install", dep])
def run_perftest(self, **kwargs): push_to_try = kwargs.pop("push_to_try", False) if push_to_try: from pathlib import Path sys.path.append(str(Path(self.topsrcdir, "tools", "tryselect"))) from tryselect.push import push_to_try platform = kwargs.pop("try_platform") if platform not in _TRY_PLATFORMS: # we can extend platform support here: linux, win, macOs, pixel2 # by adding more jobs in taskcluster/ci/perftest/kind.yml # then picking up the right one here raise NotImplementedError("%r not supported yet" % platform) perftest_parameters = {} parser = get_perftest_parser()() for name, value in kwargs.items(): # ignore values that are set to default if parser.get_default(name) == value: continue perftest_parameters[name] = value parameters = { "try_task_config": { "tasks": [_TRY_PLATFORMS[platform]], "perftest-options": perftest_parameters, }, "try_mode": "try_task_config", } task_config = {"parameters": parameters, "version": 2} push_to_try("perftest", "perftest", try_task_config=task_config) return # run locally MachCommandBase.activate_virtualenv(self) from mozperftest.runner import run_tests run_tests(mach_cmd=self, **kwargs)
def run_tests(self, **kwargs): MachCommandBase.activate_virtualenv(self) from pathlib import Path from mozperftest.runner import _setup_path from mozperftest.utils import install_package, temporary_env skip_linters = kwargs.get("skip_linters", False) # include in sys.path all deps _setup_path() try: import coverage # noqa except ImportError: pydeps = Path(self.topsrcdir, "third_party", "python") vendors = ["coverage"] if skip_linters: pypis = [] else: pypis = ["flake8"] # if we're not on try we want to install black if not ON_TRY and not skip_linters: pypis.append("black") # these are the deps we are getting from pypi for dep in pypis: install_package(self.virtualenv_manager, dep) # pip-installing dependencies that require compilation or special setup for dep in vendors: install_package(self.virtualenv_manager, str(Path(pydeps, dep))) here = Path(__file__).parent.resolve() if not ON_TRY and not skip_linters: # formatting the code with black assert self._run_python_script("black", str(here)) # checking flake8 correctness if not (ON_TRY and sys.platform == "darwin") and not skip_linters: assert self._run_python_script("flake8", str(here)) # running pytest with coverage # coverage is done in three steps: # 1/ coverage erase => erase any previous coverage data # 2/ coverage run pytest ... => run the tests and collect info # 3/ coverage report => generate the report tests_dir = Path(here, "tests").resolve() tests = kwargs.get("tests", []) if tests == []: tests = str(tests_dir) run_coverage_check = not skip_linters else: run_coverage_check = False def _get_test(test): if Path(test).exists(): return str(test) return str(tests_dir / test) tests = " ".join([_get_test(test) for test in tests]) import pytest with temporary_env(COVERAGE_RCFILE=str(here / ".coveragerc")): if run_coverage_check: assert self._run_python_script( "coverage", "erase", label="remove old coverage data" ) args = [ "run", pytest.__file__, "-xs", tests, ] assert self._run_python_script("coverage", *args, label="running tests") if run_coverage_check and not self._run_python_script( "coverage", "report", display=True ): raise ValueError("Coverage is too low!")