Skip to content

Commit d24c0a6

Browse files
authored
Use pytest-doctestplus to skip some inline doctests (#1790)
* Use pytest-doctestplus to skip some inline doctests * Install pytest-doctestplus in workflows * Add the fulltest target to run all tests, including all doctests
1 parent d4e3758 commit d24c0a6

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

.github/workflows/ci_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
pandas xarray netCDF4 packaging \
9898
${{ matrix.optional-packages }} \
9999
dvc make pytest>=6.0 \
100-
pytest-cov pytest-mpl sphinx-gallery tomli
100+
pytest-cov pytest-doctestplus pytest-mpl sphinx-gallery tomli
101101
102102
# Show installed pkg information for postmortem diagnostic
103103
- name: List installed packages

.github/workflows/ci_tests_dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
pip install --pre --prefer-binary \
9494
numpy pandas xarray netCDF4 packaging \
9595
dvc ipython 'pytest>=6.0' pytest-cov \
96-
pytest-mpl sphinx-gallery tomli
96+
pytest-doctestplus pytest-mpl sphinx-gallery tomli
9797
9898
# Pull baseline image data from dvc remote (DAGsHub)
9999
- name: Pull baseline image data from dvc remote

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ help:
1616
@echo ""
1717
@echo " install install in editable mode"
1818
@echo " package build source and wheel distributions"
19-
@echo " test run the test suite (including doctests) and report coverage"
19+
@echo " test run the test suite (including some doctests) and report coverage"
20+
@echo " fulltest run the test suite (including all doctests) and report coverage"
2021
@echo " format run black, blackdoc, docformatter and isort to automatically format the code"
2122
@echo " check run code style and quality checks (black, blackdoc, docformatter, flake8 and isort)"
2223
@echo " lint run pylint for a deeper (and slower) quality check"
@@ -31,6 +32,17 @@ package:
3132
python setup.py sdist bdist_wheel
3233

3334
test:
35+
# Run a tmp folder to make sure the tests are run on the installed version
36+
mkdir -p $(TESTDIR)
37+
@echo ""
38+
@cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).show_versions()"
39+
@echo ""
40+
cd $(TESTDIR); PYGMT_USE_EXTERNAL_DISPLAY="false" pytest $(PYTEST_COV_ARGS) --doctest-plus $(PROJECT)
41+
cp $(TESTDIR)/coverage.xml .
42+
cp -r $(TESTDIR)/htmlcov .
43+
rm -r $(TESTDIR)
44+
45+
fulltest:
3446
# Run a tmp folder to make sure the tests are run on the installed version
3547
mkdir -p $(TESTDIR)
3648
@echo ""

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies:
2727
- myst-parser
2828
- pylint
2929
- pytest-cov
30+
- pytest-doctestplus
3031
- pytest-mpl
3132
- pytest>=6.0
3233
- sphinx

pygmt/src/grdlandmask.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
grdlandmask - Create a "wet-dry" mask grid from shoreline data base
33
"""
4-
54
from pygmt.clib import Session
65
from pygmt.exceptions import GMTInvalidInput
76
from pygmt.helpers import (
@@ -13,6 +12,8 @@
1312
)
1413
from pygmt.io import load_dataarray
1514

15+
__doctest_skip__ = ["grdlandmask"]
16+
1617

1718
@fmt_docstring
1819
@use_alias(
@@ -95,12 +96,10 @@ def grdlandmask(**kwargs):
9596
9697
Example
9798
-------
98-
>>> import pygmt # doctest: +SKIP
99+
>>> import pygmt
99100
>>> # Create a landmask grid with an x-range of 125 to 130,
100101
>>> # and a y-range of 30 to 35
101-
>>> landmask = pygmt.grdlandmask(
102-
... spacing=1, region=[125, 130, 30, 35]
103-
... ) # doctest: +SKIP
102+
>>> landmask = pygmt.grdlandmask(spacing=1, region=[125, 130, 30, 35])
104103
"""
105104
if "I" not in kwargs or "R" not in kwargs:
106105
raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.")

0 commit comments

Comments
 (0)