Skip to content

Commit

Permalink
Replace pytest-cov with coverage.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Aug 26, 2022
1 parent f60a781 commit 85e4350
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 38 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pipefail
piptools
pipx
pkgcache # linux
pkgs
pluggy
podman
prerun
Expand Down
20 changes: 0 additions & 20 deletions .coveragerc

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ jobs:
# ${{ runner.os }}-
- name: Install tox
run: |
python3 -m pip install --upgrade tox 'coverage[toml]'
python3 -m pip install --upgrade tox
- name: Log installed dists
run: >-
python3 -m pip freeze --all
Expand Down Expand Up @@ -231,7 +231,7 @@ jobs:
TOXENV: ${{ matrix.tox_env }}-devel
- name: Combine coverage data
# produce a single .coverage file at repo root
run: coverage combine .tox/.coverage.*
run: tox -e coverage
- name: Upload coverage data
if: "runner.os == 'Linux'"
uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# checking if user is running pytest without installing test dependencies:
missing = []
for module in ["ansible", "black", "flake8", "flaky", "mypy", "pylint", "pytest_cov"]:
for module in ["ansible", "black", "flake8", "flaky", "mypy", "pylint"]:
if not importlib.util.find_spec(module):
missing.append(module)
if missing:
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ build-backend = "setuptools.build_meta"
target-version = ["py38"]

[tool.coverage.run]
source = ["src"]
source_pkgs = ["ansiblelint"]
branch = true
parallel = true
concurrency = ["multiprocessing", "thread"]

[tool.coverage.paths]
source = ["src", ".tox/*/site-packages"]

[tool.coverage.report]
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"]
omit = ["*/src/ansible_compat/*", "test/*"]

[tool.isort]
profile = "black"
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cffi==1.15.1
charset-normalizer==2.1.0
click==8.1.3
commonmark==0.9.1
coverage==6.4.3
coverage==6.4.4
cryptography==37.0.4
dill==0.3.5.1
docutils==0.16
Expand Down Expand Up @@ -61,7 +61,6 @@ pylint==2.14.5
pyparsing==3.0.9
pyrsistent==0.18.1
pytest==7.1.2
pytest-cov==3.0.0
pytest-forked==1.4.0
pytest-plus==0.2
pytest-xdist==2.5.0
Expand Down
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ docs =
sphinxcontrib-programoutput2 >= 2.0a1
yamllint >= 1.26.3
test =
coverage >= 6.3
tomli >= 2.0.0
coverage-enable-subprocess # see https://github.com/nedbat/coveragepy/issues/1341#issuecomment-1228942657
coverage[toml] >= 6.4.4
flaky >= 3.7.0
pytest >= 6.0.1
pytest-cov >= 2.10.1
pytest-plus >= 0.2 # for PYTEST_REQPASS
pytest-xdist >= 2.1.0
psutil # soft-dep of pytest-xdist
Expand Down
22 changes: 13 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,14 @@ commands =
{envpython} -m pip check
# we update the schemas
pytest --update-schemas
# We add coverage options but not making them mandatory as we do not want to force
# pytest users to run coverage when they just want to run a single test with `pytest -k test`
{envpython} -m pytest {posargs:\
coverage run -m pytest {posargs:\
-n auto \
-ra \
--showlocals \
--doctest-modules \
--no-success-flaky-report \
--durations=10 \
-m "not eco" \
-p pytest_cov \
--cov ansiblelint \
--cov "{envsitepackagesdir}/ansiblelint" \
--cov-report term-missing:skip-covered \
--no-cov-on-fail \
--junitxml "{toxworkdir}/junit.{envname}.xml" \
}
passenv =
CURL_CA_BUNDLE # https proxies, https://github.com/tox-dev/tox/issues/1437
Expand All @@ -62,6 +54,7 @@ setenv =
# Avoid runtime warning that might affect our devel testing
devel: ANSIBLE_DEVEL_WARNING = false
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
COVERAGE_PROCESS_START={toxinidir}/pyproject.toml
PIP_CONSTRAINT = {toxinidir}/requirements.txt
devel: PIP_CONSTRAINT = /dev/null
PIP_DISABLE_PIP_VERSION_CHECK = 1
Expand Down Expand Up @@ -215,3 +208,14 @@ deps =
commands =
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__
rm -rf .mypy_cache

[testenv:coverage]
description = Combines and displays coverage results
commands =
sh -c "coverage combine .tox/.coverage.*"
# needed by codecov github actions:
coverage xml
# just for humans running it:
coverage report --skip-covered --fail-under=88
deps =
coverage[toml]

0 comments on commit 85e4350

Please sign in to comment.