Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup some test and coverage configuration #381

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions .config/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ black==24.4.2
# via ansible-compat (pyproject.toml)
build==1.2.1
# via pip-tools
cachetools==5.3.3
# via tox
cairocffi==1.7.0
# via cairosvg
cairosvg==2.7.1
Expand All @@ -30,6 +32,10 @@ cffi==1.16.0
# via
# cairocffi
# cryptography
cfgv==3.4.0
# via pre-commit
chardet==5.2.0
# via tox
charset-normalizer==3.3.2
# via requests
click==8.1.7
Expand All @@ -42,6 +48,7 @@ colorama==0.4.6
# via
# griffe
# mkdocs-material
# tox
coverage==7.5.1
# via ansible-compat (pyproject.toml)
cryptography==42.0.7
Expand All @@ -52,16 +59,26 @@ cssselect2==0.7.0
# via cairosvg
defusedxml==0.7.1
# via cairosvg
distlib==0.3.8
# via virtualenv
dnspython==2.6.1
# via linkchecker
exceptiongroup==1.2.1
# via pytest
execnet==2.1.1
# via pytest-xdist
filelock==3.14.0
# via
# tox
# virtualenv
ghp-import==2.1.0
# via mkdocs
griffe==0.44.0
# via mkdocstrings-python
htmlmin2==0.1.13
# via mkdocs-minify-plugin
identify==2.5.36
# via pre-commit
idna==3.7
# via requests
iniconfig==2.0.0
Expand Down Expand Up @@ -145,6 +162,8 @@ mkdocstrings-python==1.10.0
# via mkdocs-ansible
mypy-extensions==1.0.0
# via black
nodeenv==1.8.0
# via pre-commit
packaging==24.0
# via
# ansible-compat (pyproject.toml)
Expand All @@ -153,7 +172,9 @@ packaging==24.0
# build
# mkdocs
# pipdeptree
# pyproject-api
# pytest
# tox
paginate==0.5.6
# via mkdocs-material
pathspec==0.12.1
Expand All @@ -177,8 +198,14 @@ platformdirs==4.2.1
# black
# mkdocs-get-deps
# mkdocstrings
# tox
# virtualenv
pluggy==1.5.0
# via pytest
# via
# pytest
# tox
pre-commit==3.7.1
# via ansible-compat (pyproject.toml)
pycparser==2.22
# via cffi
pygments==2.18.0
Expand All @@ -189,6 +216,8 @@ pymdown-extensions==10.8.1
# mkdocs-ansible
# mkdocs-material
# mkdocstrings
pyproject-api==1.6.1
# via tox
pyproject-hooks==1.1.0
# via
# build
Expand All @@ -198,10 +227,13 @@ pytest==8.2.0
# ansible-compat (pyproject.toml)
# pytest-mock
# pytest-plus
# pytest-xdist
pytest-mock==3.14.0
# via ansible-compat (pyproject.toml)
pytest-plus==0.7.0
# via ansible-compat (pyproject.toml)
pytest-xdist==3.6.1
# via ansible-compat (pyproject.toml)
python-dateutil==2.9.0.post0
# via
# ghp-import
Expand All @@ -215,6 +247,7 @@ pyyaml==6.0.1
# mkdocs
# mkdocs-get-deps
# mkdocs-macros-plugin
# pre-commit
# pymdown-extensions
# pyyaml-env-tag
pyyaml-env-tag==0.1
Expand All @@ -235,7 +268,9 @@ rpds-py==0.18.1
# jsonschema
# referencing
setuptools==69.5.1
# via pip-tools
# via
# nodeenv
# pip-tools
six==1.16.0
# via python-dateutil
soupsieve==2.5
Expand All @@ -256,11 +291,19 @@ tomli==2.0.1
# black
# build
# pip-tools
# pyproject-api
# pytest
# tox
tox==4.15.0
# via ansible-compat (pyproject.toml)
typing-extensions==4.11.0
# via black
urllib3==2.2.1
# via requests
virtualenv==20.26.2
# via
# pre-commit
# tox
watchdog==4.0.0
# via mkdocs
webencodings==0.5.1
Expand Down
3 changes: 3 additions & 0 deletions .config/requirements-test.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
coverage
pip-tools
pre-commit
pytest-mock
pytest-plus>=0.6.1
pytest-xdist
pytest>=7.2.0
tox
12 changes: 9 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ changelog = "https://github.com/ansible/ansible-compat/releases"

[tool.coverage.report]
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"]
fail_under = 92
skip_covered = true
fail_under = 98
show_missing = true
skip_covered = true
skip_empty = true
sort = "Cover"


[tool.coverage.run]
source = ["src"]
source_pkgs = ["ansible_compat"]
# Do not use branch until bug is fixes:
# https://github.com/nedbat/coveragepy/issues/605
branch = false
Expand Down Expand Up @@ -336,6 +339,7 @@ disable = [
]

[tool.pytest.ini_options]
addopts = "-ra --showlocals --durations=10"
# ensure we treat warnings as error
filterwarnings = [
"error",
Expand All @@ -344,6 +348,8 @@ filterwarnings = [
"ignore:'importlib.abc.TraversableResources' is deprecated and slated for removal in Python 3.14:DeprecationWarning",
]
testpaths = ["test"]
tmp_path_retention_policy = "failed"
verbosity_assertions = 2

[tool.ruff]
target-version = "py39"
Expand Down
15 changes: 10 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ commands_pre =
# safety measure to assure we do not accidentally run tests with broken dependencies
{envpython} -m pip check
# cleaning needed to prevent errors between runs
sh -c "rm -f {envdir}/.coverage.* 2>/dev/null || true"
sh -c "rm -f {envdir}/.coverage* 2>/dev/null || true"
commands =
sh -c "ansible --version | head -n 1"
# Add the pth file for coverage + xdist reporting
python -c 'import pathlib; pathlib.Path("{env_site_packages_dir}/cov.pth").write_text("import coverage; coverage.process_startup()")'
# 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`
coverage run -m pytest {posargs:}
# needed for upload to codecov.io
{py,py39,py310,py311,py312,py313}: sh -c "coverage combine -q --data-file={envdir}/.coverage {envdir}/.coverage.* && coverage xml --data-file={envdir}/.coverage -o {envdir}/coverage.xml --ignore-errors --fail-under=0 && COVERAGE_FILE={envdir}/.coverage coverage lcov --fail-under=0 --ignore-errors -q && COVERAGE_FILE={envdir}/.coverage coverage report --fail-under=0 --ignore-errors"
# lcov needed for vscode integration due to https://github.com/ryanluker/vscode-coverage-gutters/issues/403
coverage run -m pytest {posargs:-n auto}
{py,py39,py310,py311,py312,py313}: sh -c " \
coverage combine -q --data-file={envdir}/.coverage {envdir}/.coverage.* && \
coverage xml --data-file={envdir}/.coverage -o {envdir}/coverage.xml --ignore-errors --fail-under=0 && \
COVERAGE_FILE={envdir}/.coverage coverage lcov --fail-under=0 --ignore-errors -q && \
COVERAGE_FILE={envdir}/.coverage coverage report --ignore-errors \
"
# We fail if files are modified at the end
git diff --exit-code

Expand Down
Loading