Skip to content

Commit

Permalink
Merge branch 'mr/ramonat/e3-pytest-without-coverage' into 'master'
Browse files Browse the repository at this point in the history
Do not force the use of the coverage package with e3.pytest

See merge request it/e3-core!105
  • Loading branch information
enzbang committed Feb 17, 2025
2 parents ab54215 + 9eba3f4 commit 2764bd4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Repository = "https://github.com/AdaCore/e3-core"

[project.optional-dependencies]
test = [
"coverage",
"mock",
"requests-mock",
"pytest",
Expand Down
16 changes: 9 additions & 7 deletions src/e3/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ passenv = CI,GITHUB_*,CODECOV_*

deps =
xdist: pytest-xdist[psutil]
pytest-cov
cov: pytest-cov
codecov: codecov
extras = test

Expand Down

0 comments on commit 2764bd4

Please sign in to comment.