Skip to content

Commit

Permalink
Add coverage testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lbdreyer committed Feb 21, 2023
1 parent 11da71b commit 561e64d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ jobs:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10"]
session: ["tests", "doctest", "gallery", "linkcheck"]
session: ["doctest", "gallery", "linkcheck"]
include:
- os: "ubuntu-latest"
python-version: "3.10"
session: "tests"
coverage: True
- os: "ubuntu-latest"
python-version: "3.9"
session: "tests"
Expand Down Expand Up @@ -132,5 +136,10 @@ jobs:
- name: "iris ${{ matrix.session }}"
env:
PY_VER: ${{ matrix.python-version }}
COVERAGE: ${{ matrix.coverage }}
run: |
nox --session ${{ matrix.session }} -- --verbose
- name: Upload coverage report
uses: codecov/codecov-action@v3
if: ${{ matrix.coverage }}
6 changes: 6 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ This document explains the changes made to Iris for this release
#. `@rcomer`_ removed some old infrastructure that printed test timings.
(:pull:`5101`)

#. `@lbdreyer`_ and `@trexfeathers`_ (reviewer) added coverage testing. This can
be enabled by setting the environment variable ``COVERAGE=True`` when running
the tests with nox, i.e. ``nox --session tests``. (:pull:`4765`)

#. `@lbdreyer`_ and `@trexfeathers`_ (reviewer) removed the ``--coding-tests``
option from Iris' test runner. (:pull:`4765`)

.. comment
Whatsnew author names (@github name) in alphabetical order. Note that,
Expand Down
18 changes: 6 additions & 12 deletions lib/iris/tests/runner/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,22 @@ class TestRunner:
("system-tests", "s", "Run the limited subset of system tests."),
("gallery-tests", "e", "Run the gallery code tests."),
("default-tests", "d", "Run the default tests."),
(
"coding-tests",
"c",
"Run the coding standards tests. (These are a "
"subset of the default tests.)",
),
(
"num-processors=",
"p",
"The number of processors used for running " "the tests.",
),
("create-missing", "m", "Create missing test result files."),
("coverage", "c", "Enable coverage testing"),
]
boolean_options = [
"no-data",
"system-tests",
"stop",
"gallery-tests",
"default-tests",
"coding-tests",
"create-missing",
"coverage",
]

def initialize_options(self):
Expand All @@ -64,9 +59,9 @@ def initialize_options(self):
self.system_tests = False
self.gallery_tests = False
self.default_tests = False
self.coding_tests = False
self.num_processors = None
self.create_missing = False
self.coverage = False

def finalize_options(self):
# These environment variables will be propagated to all the
Expand All @@ -84,8 +79,6 @@ def finalize_options(self):
tests.append("system")
if self.default_tests:
tests.append("default")
if self.coding_tests:
tests.append("coding")
if self.gallery_tests:
tests.append("gallery")
if not tests:
Expand All @@ -109,8 +102,6 @@ def run(self):
tests.append("lib/iris/tests/system_test.py")
if self.default_tests:
tests.append("lib/iris/tests")
if self.coding_tests:
tests.append("lib/iris/tests/test_coding_standards.py")
if self.gallery_tests:
import iris.config

Expand All @@ -136,6 +127,9 @@ def run(self):
if self.stop:
args.append("-x")

if self.coverage:
args.extend(["--cov=lib/iris", "--cov-report=xml"])

result = True
for test in tests:
args[0] = test
Expand Down
12 changes: 9 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#: Cirrus-CI environment variable hook.
PY_VER = os.environ.get("PY_VER", _PY_VERSIONS_ALL)
COVERAGE = os.environ.get("COVERAGE", False)

#: Default cartopy cache directory.
CARTOPY_CACHE_DIR = os.environ.get("HOME") / Path(".local/share/cartopy")
Expand Down Expand Up @@ -176,6 +177,9 @@ def tests(session: nox.sessions.Session):
"""
Perform iris system, integration and unit tests.
Coverage testing is enabled if the COVERAGE environment variable is set to
True.
Parameters
----------
session: object
Expand All @@ -185,13 +189,15 @@ def tests(session: nox.sessions.Session):
prepare_venv(session)
session.install("--no-deps", "--editable", ".")
session.env.update(ENV)
session.run(
run_args = [
"python",
"-m",
"iris.tests.runner",
"--default-tests",
"--system-tests",
)
]
if COVERAGE:
run_args.append("--coverage")
session.run(*run_args)


@nox.session(python=_PY_VERSION_DOCSBUILD, venv_backend="conda")
Expand Down
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,20 @@ verbose = "False"
[tool.pytest.ini_options]
addopts = "-ra"
testpaths = "lib/iris"

[tool.coverage.run]
branch = true
source = [
"lib/iris",
]
omit = [
"lib/iris/tests/*",
"lib/iris/etc/*",
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if __name__ == .__main__.:"
]
1 change: 1 addition & 0 deletions requirements/ci/py310.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies:
- pre-commit
- psutil
- pytest
- pytest-cov
- pytest-xdist
- requests

Expand Down

0 comments on commit 561e64d

Please sign in to comment.