Skip to content

Commit 2c0a437

Browse files
committed
Add coverage testing
1 parent ca42c30 commit 2c0a437

File tree

7 files changed

+57
-22
lines changed

7 files changed

+57
-22
lines changed

.github/workflows/ci-tests.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ jobs:
3636
matrix:
3737
os: ["ubuntu-latest"]
3838
python-version: ["3.10"]
39-
session: ["tests", "doctest", "gallery", "linkcheck"]
39+
session: ["doctest", "gallery", "linkcheck"]
4040
include:
41+
- os: "ubuntu-latest"
42+
python-version: "3.10"
43+
session: "tests"
44+
coverage: True
4145
- os: "ubuntu-latest"
4246
python-version: "3.9"
4347
session: "tests"
@@ -132,5 +136,10 @@ jobs:
132136
- name: "iris ${{ matrix.session }}"
133137
env:
134138
PY_VER: ${{ matrix.python-version }}
139+
COVERAGE: ${{ matrix.coverage }}
135140
run: |
136141
nox --session ${{ matrix.session }} -- --verbose
142+
143+
- name: Upload coverage report
144+
uses: codecov/codecov-action@v3
145+
if: ${{ matrix.coverage }}

docs/src/whatsnew/latest.rst

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ This document explains the changes made to Iris for this release
108108
#. `@rcomer`_ removed some old infrastructure that printed test timings.
109109
(:pull:`5101`)
110110

111+
#. `@lbdreyer`_ and `@trexfeathers`_ (reviewer) added coverage testing. This can
112+
be enabled by setting the environment variable ``COVERAGE=True`` when running
113+
the tests with nox, i.e. ``nox --session tests``. (:pull:`4765`)
114+
115+
#. `@lbdreyer`_ and `@trexfeathers`_ (reviewer) removed the ``--coding-tests``
116+
option from Iris' test runner. (:pull:`4765`)
111117

112118
.. comment
113119
Whatsnew author names (@github name) in alphabetical order. Note that,

lib/iris/tests/runner/_runner.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,22 @@ class TestRunner:
3535
("system-tests", "s", "Run the limited subset of system tests."),
3636
("gallery-tests", "e", "Run the gallery code tests."),
3737
("default-tests", "d", "Run the default tests."),
38-
(
39-
"coding-tests",
40-
"c",
41-
"Run the coding standards tests. (These are a "
42-
"subset of the default tests.)",
43-
),
4438
(
4539
"num-processors=",
4640
"p",
4741
"The number of processors used for running " "the tests.",
4842
),
4943
("create-missing", "m", "Create missing test result files."),
44+
("coverage", "c", "Enable coverage testing"),
5045
]
5146
boolean_options = [
5247
"no-data",
5348
"system-tests",
5449
"stop",
5550
"gallery-tests",
5651
"default-tests",
57-
"coding-tests",
5852
"create-missing",
53+
"coverage",
5954
]
6055

6156
def initialize_options(self):
@@ -64,9 +59,9 @@ def initialize_options(self):
6459
self.system_tests = False
6560
self.gallery_tests = False
6661
self.default_tests = False
67-
self.coding_tests = False
6862
self.num_processors = None
6963
self.create_missing = False
64+
self.coverage = False
7065

7166
def finalize_options(self):
7267
# These environment variables will be propagated to all the
@@ -84,8 +79,6 @@ def finalize_options(self):
8479
tests.append("system")
8580
if self.default_tests:
8681
tests.append("default")
87-
if self.coding_tests:
88-
tests.append("coding")
8982
if self.gallery_tests:
9083
tests.append("gallery")
9184
if not tests:
@@ -109,8 +102,6 @@ def run(self):
109102
tests.append("lib/iris/tests/system_test.py")
110103
if self.default_tests:
111104
tests.append("lib/iris/tests")
112-
if self.coding_tests:
113-
tests.append("lib/iris/tests/test_coding_standards.py")
114105
if self.gallery_tests:
115106
import iris.config
116107

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

130+
if self.coverage:
131+
args.extend(["--cov=lib/iris", "--cov-report=xml"])
132+
139133
result = True
140134
for test in tests:
141135
args[0] = test

noxfile.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

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

3233
#: Default cartopy cache directory.
3334
CARTOPY_CACHE_DIR = os.environ.get("HOME") / Path(".local/share/cartopy")
@@ -176,6 +177,9 @@ def tests(session: nox.sessions.Session):
176177
"""
177178
Perform iris system, integration and unit tests.
178179
180+
Coverage testing is enabled if the COVERAGE environment variable is set to
181+
True.
182+
179183
Parameters
180184
----------
181185
session: object
@@ -185,13 +189,15 @@ def tests(session: nox.sessions.Session):
185189
prepare_venv(session)
186190
session.install("--no-deps", "--editable", ".")
187191
session.env.update(ENV)
188-
session.run(
192+
run_args = [
189193
"python",
190194
"-m",
191195
"iris.tests.runner",
192196
"--default-tests",
193-
"--system-tests",
194-
)
197+
]
198+
if COVERAGE:
199+
run_args.append("--coverage")
200+
session.run(*run_args)
195201

196202

197203
@nox.session(python=_PY_VERSION_DOCSBUILD, venv_backend="conda")

pyproject.toml

+17
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,20 @@ verbose = "False"
4646
[tool.pytest.ini_options]
4747
addopts = "-ra"
4848
testpaths = "lib/iris"
49+
50+
[tool.coverage.run]
51+
branch = true
52+
source = [
53+
"lib/iris",
54+
]
55+
omit = [
56+
"lib/iris/tests/*",
57+
"lib/iris/etc/*",
58+
]
59+
60+
[tool.coverage.report]
61+
exclude_lines = [
62+
"pragma: no cover",
63+
"def __repr__",
64+
"if __name__ == .__main__.:"
65+
]

requirements/ci/nox.lock/py310-linux-64.lock

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Generated by conda-lock.
22
# platform: linux-64
3-
# input_hash: 234b47d943728b5abe70fba0fd74c6adc10e4f1e2a14b919344f8a693b5b3e6f
3+
# input_hash: f8af5f4aafcb766f463a1a897d3dab9e04f05f1494bced5931d78175ca0c66df
44
@EXPLICIT
55
https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2#d7c89558ba9fa0495403155b64376d81
66
https://conda.anaconda.org/conda-forge/linux-64/ca-certificates-2022.12.7-ha878542_0.conda#ff9f73d45c4a07d6f424495288a26080
@@ -150,7 +150,7 @@ https://conda.anaconda.org/conda-forge/linux-64/kiwisolver-1.4.4-py310hbf28c38_1
150150
https://conda.anaconda.org/conda-forge/linux-64/lcms2-2.14-hfd0df8a_1.conda#c2566c2ea5f153ddd6bf4acaf7547d97
151151
https://conda.anaconda.org/conda-forge/linux-64/libclang13-15.0.7-default_h3e3d535_1.conda#a3a0f7a6f0885f5e1e0ec691566afb77
152152
https://conda.anaconda.org/conda-forge/linux-64/libcups-2.3.3-h36d4200_3.conda#c9f4416a34bc91e0eb029f912c68f81f
153-
https://conda.anaconda.org/conda-forge/linux-64/libcurl-7.88.0-hdc1c0ab_0.conda#c44acb3847ff118c068b662aff858afd
153+
https://conda.anaconda.org/conda-forge/linux-64/libcurl-7.88.1-hdc1c0ab_0.conda#81eaeb3b35163c8e90e57532bc93754d
154154
https://conda.anaconda.org/conda-forge/linux-64/libpq-15.2-hb675445_0.conda#4654b17eccaba55b8581d6b9c77f53cc
155155
https://conda.anaconda.org/conda-forge/linux-64/libsystemd0-252-h2a991cd_0.tar.bz2#3c5ae9f61f663b3d5e1bf7f7da0c85f5
156156
https://conda.anaconda.org/conda-forge/linux-64/libwebp-1.2.4-h1daa5a0_1.conda#77003f63d1763c1e6569a02c1742c9f4
@@ -191,14 +191,15 @@ https://conda.anaconda.org/conda-forge/noarch/wheel-0.38.4-pyhd8ed1ab_0.tar.bz2#
191191
https://conda.anaconda.org/conda-forge/linux-64/xcb-util-image-0.4.0-h166bdaf_0.tar.bz2#c9b568bd804cb2903c6be6f5f68182e4
192192
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxext-1.3.4-h7f98852_1.tar.bz2#536cc5db4d0a3ba0630541aec064b5e4
193193
https://conda.anaconda.org/conda-forge/linux-64/xorg-libxrender-0.9.10-h7f98852_1003.tar.bz2#f59c1242cc1dd93e72c2ee2b360979eb
194-
https://conda.anaconda.org/conda-forge/noarch/zipp-3.13.0-pyhd8ed1ab_0.conda#41b09d997939e83b231c4557a90c3b13
194+
https://conda.anaconda.org/conda-forge/noarch/zipp-3.14.0-pyhd8ed1ab_0.conda#01ea04980fa39d7b6dbdd6c67016d177
195195
https://conda.anaconda.org/conda-forge/noarch/babel-2.11.0-pyhd8ed1ab_0.tar.bz2#2ea70fde8d581ba9425a761609eed6ba
196196
https://conda.anaconda.org/conda-forge/noarch/beautifulsoup4-4.11.2-pyha770c72_0.conda#88b59f6989f0ed5ab3433af0b82555e1
197197
https://conda.anaconda.org/conda-forge/linux-64/cairo-1.16.0-ha61ee94_1014.tar.bz2#d1a88f3ed5b52e1024b80d4bcd26a7a0
198198
https://conda.anaconda.org/conda-forge/linux-64/cffi-1.15.1-py310h255011f_3.conda#800596144bb613cd7ac58b80900ce835
199199
https://conda.anaconda.org/conda-forge/linux-64/cftime-1.6.2-py310hde88566_1.tar.bz2#94ce7a76b0c912279f6958e0b6b21d2b
200200
https://conda.anaconda.org/conda-forge/linux-64/contourpy-1.0.7-py310hdf3cbec_0.conda#7bf9d8c765b6b04882c719509652c6d6
201-
https://conda.anaconda.org/conda-forge/linux-64/curl-7.88.0-hdc1c0ab_0.conda#5d9ac94ee84305ada32c3d287d0ec602
201+
https://conda.anaconda.org/conda-forge/linux-64/coverage-7.1.0-py310h1fa729e_0.conda#da7c45dbe780f5e162011a3af44e5009
202+
https://conda.anaconda.org/conda-forge/linux-64/curl-7.88.1-hdc1c0ab_0.conda#1968e4fef727858ac04746560e820928
202203
https://conda.anaconda.org/conda-forge/linux-64/fonttools-4.38.0-py310h5764c6d_1.tar.bz2#12ebe92a8a578bc903bd844744f4d040
203204
https://conda.anaconda.org/conda-forge/linux-64/glib-2.74.1-h6239696_1.tar.bz2#f3220a9e9d3abcbfca43419a219df7e4
204205
https://conda.anaconda.org/conda-forge/linux-64/hdf5-1.12.2-mpi_mpich_h5d83325_1.conda#811c4d55cf17b42336ffa314239717b0
@@ -234,6 +235,7 @@ https://conda.anaconda.org/conda-forge/linux-64/pandas-1.5.3-py310h9b08913_0.con
234235
https://conda.anaconda.org/conda-forge/noarch/platformdirs-3.0.0-pyhd8ed1ab_0.conda#c34694044915d7f291ef257029f2e2af
235236
https://conda.anaconda.org/conda-forge/linux-64/pyproj-3.4.1-py310h15e2413_1.conda#5be35366687def87437d210fd673100c
236237
https://conda.anaconda.org/conda-forge/linux-64/pyqt5-sip-12.11.0-py310heca2aa9_3.conda#3b1946b676534472ce65181dda0b9554
238+
https://conda.anaconda.org/conda-forge/noarch/pytest-cov-4.0.0-pyhd8ed1ab_0.tar.bz2#c9e3f8bfdb9bfc34aa1836a6ed4b25d7
237239
https://conda.anaconda.org/conda-forge/noarch/pytest-xdist-3.2.0-pyhd8ed1ab_0.conda#70ab87b96126f35d1e68de2ad9fb6423
238240
https://conda.anaconda.org/conda-forge/noarch/setuptools-scm-7.1.0-pyhd8ed1ab_0.conda#6613dbb3b25cc648a107f33ca9f80fc1
239241
https://conda.anaconda.org/conda-forge/noarch/sphinxcontrib-napoleon-0.7-py_0.tar.bz2#0bc25ff6f2e34af63ded59692df5f749
@@ -242,8 +244,8 @@ https://conda.anaconda.org/conda-forge/linux-64/gst-plugins-base-1.22.0-h4243ec0
242244
https://conda.anaconda.org/conda-forge/noarch/identify-2.5.18-pyhd8ed1ab_0.conda#e07a5691c27e65d8d3d9278c578c7771
243245
https://conda.anaconda.org/conda-forge/noarch/nc-time-axis-1.4.1-pyhd8ed1ab_0.tar.bz2#281b58948bf60a2582de9e548bcc5369
244246
https://conda.anaconda.org/conda-forge/linux-64/netcdf-fortran-4.6.0-mpi_mpich_h1e13492_2.conda#d4ed7704f0fa589e4d7656780fa87557
245-
https://conda.anaconda.org/conda-forge/linux-64/netcdf4-1.6.0-nompi_py310h0a86a1f_103.conda#7f69695b684f2595d9ba1ce26d693b7d
246-
https://conda.anaconda.org/conda-forge/linux-64/pango-1.50.12-hd33c08f_1.conda#667dc93c913f0156e1237032e3a22046
247+
https://conda.anaconda.org/conda-forge/linux-64/netcdf4-1.6.2-nompi_py310h55e1e36_100.tar.bz2#4dd7aa28fb7d9a6de061c9579a30e7dd
248+
https://conda.anaconda.org/conda-forge/linux-64/pango-1.50.13-hd33c08f_0.conda#e3b13445b8ee9d6a3d53a714f89ccd76
247249
https://conda.anaconda.org/conda-forge/linux-64/parallelio-2.5.10-mpi_mpich_h862c5c2_100.conda#56e43c5226670aa0943fae9a2628a934
248250
https://conda.anaconda.org/conda-forge/noarch/pyopenssl-23.0.0-pyhd8ed1ab_0.conda#d41957700e83bbb925928764cb7f8878
249251
https://conda.anaconda.org/conda-forge/noarch/virtualenv-20.19.0-pyhd8ed1ab_0.conda#afaa9bf6992f67a82d75fad47a93ec84

requirements/ci/py310.yml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies:
3939
- pre-commit
4040
- psutil
4141
- pytest
42+
- pytest-cov
4243
- pytest-xdist
4344
- requests
4445

0 commit comments

Comments
 (0)