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 # include in sys.path all deps _setup_path() try: import black # noqa except ImportError: # install the tests scripts in the virtualenv # this step will be removed once Bug 1635573 is done # so we don't have to hit pypi or our internal mirror at all pydeps = Path(self.topsrcdir, "third_party", "python") for name in ( # installing pyrsistent and attrs so we don't pick newer ones str(pydeps / "pyrsistent"), str(pydeps / "attrs"), "coverage", "black", "flake8", ): install_package(self.virtualenv_manager, name) here = Path(__file__).parent.resolve() if not ON_TRY: # formatting the code with black assert self._run_python_script("black", str(here)) # checking flake8 correctness 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 = here / "tests" import pytest with temporary_env(COVERAGE_RCFILE=str(here / ".coveragerc")): assert self._run_python_script("coverage", "erase", label="remove old coverage data") args = [ "run", pytest.__file__, "-xs", str(tests.resolve()), ] assert self._run_python_script("coverage", *args, label="running tests") if not self._run_python_script("coverage", "report", display=True): raise ValueError("Coverage is too low!")
def _run_tests(self, **kwargs): from pathlib import Path from mozperftest.runner import _setup_path from mozperftest.utils import install_package, ON_TRY skip_linters = kwargs.get("skip_linters", False) verbose = kwargs.get("verbose", 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 not ON_TRY: vendors.append("attrs") # pip-installing dependencies that require compilation or special setup for dep in vendors: install_package(self.virtualenv_manager, str(Path(pydeps, dep))) if not ON_TRY and not skip_linters: cmd = "./mach lint " if verbose: cmd += " -v" cmd += " " + str(HERE) if not self._run_script( cmd, label="linters", display=verbose, verbose=verbose): raise AssertionError("Please fix your code.") # 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 options = "-xs" if kwargs.get("verbose"): options += "v" if run_coverage_check: assert self._run_python_script("coverage", "erase", label="remove old coverage data") args = [ "run", pytest.__file__, options, "--duration", "10", tests, ] assert self._run_python_script("coverage", *args, label="running tests", verbose=verbose, display=verbose) if run_coverage_check and not self._run_python_script( "coverage", "report", display=True): raise ValueError("Coverage is too low!")
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!")