diff --git a/pyproject.toml b/pyproject.toml index ac656411..b80be3f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,6 @@ Repository = "https://github.com/AdaCore/e3-core" [project.optional-dependencies] test = [ - "coverage", "mock", "requests-mock", "pytest", diff --git a/src/e3/pytest.py b/src/e3/pytest.py index 9078d00a..03531b9c 100644 --- a/src/e3/pytest.py +++ b/src/e3/pytest.py @@ -13,18 +13,12 @@ try: import pytest - from coverage.sqldata import CoverageData - from coverage.files import PathAliases - from coverage import Coverage except ImportError as ie: # defensive code # Those packages may be missing. In order to avoid importing tests or # coverage packages in release mode, they are deliberately not part of # the dependencies. Let the user know that the packages should be installed # if he wants to use e3 pytest driver. - raise ImportError( - "Missing test and coverage packages. Please install pytest and coverage " - "packages" - ) from ie + raise ImportError("The e3.pytest plugin requires the pytest package") from ie import typing @@ -143,6 +137,9 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None: if hasattr(session.config.option, "cov_source") and session.config.getoption( "cov_source" ): + # Load only the coverage package if it was activated using the --cov option + from coverage import Coverage + cov_file = str(session.config.rootpath / ".coverage") if hasattr( session.config.option, "e3_cov_rewrite" @@ -205,6 +202,11 @@ def fix_coverage_paths(origin_dir: str, new_dir: str, cov_db: str) -> None: e.g. src/ :param cov_db: path to the .coverage database """ + # Only import packages from coverage if needed, the pytest plugin can + # be used without coverage. + from coverage.sqldata import CoverageData + from coverage.files import PathAliases + paths = PathAliases() paths.add(origin_dir, new_dir) diff --git a/tox.ini b/tox.ini index 33ba5992..eddd2fe0 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ passenv = CI,GITHUB_*,CODECOV_* deps = xdist: pytest-xdist[psutil] - pytest-cov + cov: pytest-cov codecov: codecov extras = test