diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..e8cb87d --- /dev/null +++ b/.coveragerc @@ -0,0 +1,29 @@ +# Coverage configuration. +# +# This lives in a dedicated .coveragerc (INI) rather than pyproject.toml so +# that it can be read by any coverage install. The OpenAstronomy tox workflow +# runs `coverage combine`/`coverage xml` in the repo root via `uvx coverage`, +# which installs a bare `coverage` without the `[toml]` extra. On Python < 3.11 +# (no stdlib tomllib) that build cannot parse a pyproject.toml config and fails +# with "Can't read 'pyproject.toml' without TOML support". +[run] +omit = tests/* + +[report] +exclude_lines = + # Have to re-enable the standard pragma + # and branches that don't pertain to this version of Python + pragma: no cover + pragma: py{ignore_python_version} + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + # Don't complain if non-runnable code isn't run + if __name__ == .__main__.: + # Don't complain about abstract methods, they aren't run: + @(abc\.)?abstractmethod + # Exclude type check blocks and Protocol contents, they aren't run: + if TYPE_CHECKING: + \.\.\. + # Don't complain about IPython completion helper + def _ipython_key_completions_ diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index df89031..86ed41c 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -52,12 +52,12 @@ jobs: - linux: py310-test-cov - linux: py312-test-cov # All deps tests - - linux: py311-test-alldeps + - linux: py311-test-alldeps-cov toxargs: '-v --develop' - linux: py39-test-oldestdeps-alldeps-cov-clocale # Platform test - - windows: py311-test-alldeps - # - macos: py311-test-alldeps # TODO: https://github.com/OpenAstronomy/github-actions-workflows/issues/197 + - windows: py311-test-alldeps-cov + # - macos: py311-test-alldeps-cov # TODO: https://github.com/OpenAstronomy/github-actions-workflows/issues/197 conda: false coverage: codecov diff --git a/pyproject.toml b/pyproject.toml index 6b23074..7b36b5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,28 +57,8 @@ documentation = "https://cosmology.readthedocs.org/projects/api" -[tool.coverage.run] - omit = ["tests/*"] - -[tool.coverage.report] - exclude_lines = [ - # Have to re-enable the standard pragma - # and branches that don't pertain to this version of Python - "pragma: no cover", - "pragma: py{ignore_python_version}", - # Don't complain if tests don't hit defensive assertion code: - "raise AssertionError", - "raise NotImplementedError", - # Don't complain if non-runnable code isn't run - "if __name__ == .__main__.:", - # Don't complain about abstract methods, they aren't run: - '@(abc\.)?abstractmethod', - # Exclude type check blocks and Protocol contents, they aren't run: - "if TYPE_CHECKING:", - '\.\.\.', - # Don't complain about IPython completion helper - "def _ipython_key_completions_", - ] +# NOTE: coverage configuration lives in .coveragerc (not here) so that the +# bare `coverage` used by the CI workflow can read it without TOML support. [tool.hatch] build.targets.sdist.exclude = [ diff --git a/tox.ini b/tox.ini index 1a6a7b0..7f015fb 100644 --- a/tox.ini +++ b/tox.ini @@ -73,7 +73,7 @@ extras = commands = pip freeze !cov-!double: pytest --pyargs {toxinidir}/tests {toxinidir}/docs {posargs} - cov-!double: pytest --pyargs {toxinidir}/tests {toxinidir}/docs --cov cosmology --cov-config={toxinidir}/pyproject.toml {posargs} + cov-!double: pytest --pyargs {toxinidir}/tests {toxinidir}/docs --cov cosmology --cov-config={toxinidir}/.coveragerc {posargs} cov: coverage xml -o {toxinidir}/coverage.xml