Skip to content

Commit

Permalink
Maintenance of testing and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
shatakshiiii authored and ssbarnea committed Jan 4, 2024
1 parent 22303d5 commit 57beb3b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 22 deletions.
41 changes: 32 additions & 9 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # needed by setuptools-scm
submodules: true

- name: Set pre-commit cache
uses: actions/cache@v3
if: ${{ matrix.passed_name == 'lint' }}
with:
path: |
~/.cache/pre-commit
key: pre-commit-${{ matrix.name || matrix.passed_name }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
cache: pip
python-version: ${{ matrix.python_version || '3.10' }}

- name: Install tox
run: python3 -m pip install --upgrade "tox>=4.0.2"
Expand All @@ -63,15 +72,29 @@ jobs:
continue-on-error: ${{ matrix.devel || false }}
run: python3 -m tox -e ${{ matrix.passed_name }}

# - name: Upload coverage data
# if: ${{ startsWith(matrix.passed_name, 'py') }}
# uses: codecov/codecov-action@v3
# with:
# name: ${{ matrix.passed_name }}
# fail_ci_if_error: false # see https://github.com/codecov/codecov-action/issues/598
# token: ${{ secrets.CODECOV_TOKEN }}
# verbose: true # optional (default = false)
- name: Upload coverage data
if: ${{ startsWith(matrix.passed_name, 'py') }}
uses: codecov/codecov-action@v3
with:
name: ${{ matrix.passed_name }}
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true # optional (default = false)

- name: Archive logs
uses: actions/upload-artifact@v3
with:
name: logs.zip
path: .tox/**/log/

- name: Report failure if git reports dirty status
run: |
if [[ -n $(git status -s) ]]; then
# shellcheck disable=SC2016
echo -n '::error file=git-status::'
printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY"
exit 99
fi
# https://github.com/actions/toolkit/issues/193
tox_passed:
needs: tox
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ repos:
rev: "1.3.1"
hooks:
- id: tox-ini-fmt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.11"
hooks:
Expand Down
27 changes: 23 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=63", # required by pyproject+setuptools_scm integration
"setuptools_scm[toml]>=7.0.5" # required for "no-local-version" scheme
"setuptools >= 65.3.0", # required by pyproject+setuptools_scm integration and editable installs
"setuptools_scm[toml] >= 7.0.5" # required for "no-local-version" scheme
]
build-backend = "setuptools.build_meta"

[project]
name = "tox-ansible"
Expand Down Expand Up @@ -41,6 +41,25 @@ tox-ansible = "tox_ansible.plugin"
[tool.black]
line-length = 100

# Keep this default because xml/report do not know to use load it from config file:
# data_file = ".coverage"
[tool.coverage.paths]
source = ["src", ".tox/*/site-packages"]

[tool.coverage.report]
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"]
omit = ["tests/*"]
# Increase it just so it would pass on any single-python run
fail_under = 21
# skip_covered = true
# skip_empty = true
# During development we might remove code (files) with coverage data, and we dont want to fail:
ignore_errors = true
show_missing = true

[tool.coverage.run]
source = ["src"]

[tool.pydoclint]
allow-init-docstring = true
arg-type-hints-in-docstring = false
Expand Down Expand Up @@ -74,7 +93,7 @@ enable = [
]

[tool.pytest.ini_options]
addopts = "-n=auto --dist=loadfile --maxfail=10 --durations=30 --showlocals"
addopts = "--maxfail=10 --durations=30 --showlocals"

[tool.ruff]
fix = true
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ def pytest_generate_tests(metafunc: Metafunc) -> None:
metafunc.parametrize(
"basic_environment",
environment_configs,
ids=configs.sections(),
ids=[x.replace(":", "-") for x in configs.sections()],
)
8 changes: 8 additions & 0 deletions tests/integration/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import pytest

from tox_ansible.plugin import conf_passenv


if TYPE_CHECKING:
from pathlib import Path
Expand Down Expand Up @@ -92,3 +94,9 @@ def test_environment_config(

assert "https://github.com/ansible/ansible/archive" in config["deps"]
assert "XDG_CACHE_HOME" in config["set_env"]


def test_import() -> None:
"""Verify that module can be imported (used for coverage)."""
x = conf_passenv()
assert "GITHUB_TOKEN" in x
21 changes: 14 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tox]
requires =
tox>=4.2
setuptools>=65.3
tox>=4.6.3
env_list =
py
lint
Expand All @@ -11,38 +12,44 @@ skip_missing_interpreters = true
work_dir = {env:TOX_WORK_DIR:.tox}

[testenv]
description = Run pytest under {basepython} ({envpython})
description = Run pytest under {basepython}
package = editable
extras =
test
pass_env =
CI
CONTAINER_*
COVERAGE_*
DOCKER_*
GITHUB_*
HOME
LANG
LC_*
PYTEST_*
SSH_AUTH_SOCK
TERM
USER
set_env =
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
COVERAGE_PROCESS_START = {toxinidir}/pyproject.toml
FORCE_COLOR = 1
PIP_CONSTRAINT = {toxinidir}/requirements.txt
PRE_COMMIT_COLOR = always
TERM = xterm-256color
py38, py39: PIP_CONSTRAINT = /dev/null
lint, py38, py39: PIP_CONSTRAINT = /dev/null
commands_pre =
sh -c "rm -f .tox/.coverage* **/*.pyc 2>/dev/null || true"
commands =
pip freeze
coverage run -m pytest {posargs}
sh -c "coverage combine -q .tox/.coverage.* && coverage xml || true && coverage report"
coverage report
coverage xml
allowlist_externals =
git
rm
sh
editable = true

[testenv:lint]
description = Enforce quality standards under {basepython} ({envpython})
description = Enforce quality standards under {basepython}
skip_install = true
deps =
pre-commit
Expand Down

0 comments on commit 57beb3b

Please sign in to comment.