From 92d6d30f42d5b0d2e280fa220e34276975af2fbf Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 8 Mar 2022 11:01:05 +0800 Subject: [PATCH] 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 --- .github/workflows/ci_tests.yaml | 2 +- .github/workflows/ci_tests_dev.yaml | 2 +- Makefile | 14 +++++++++++++- environment.yml | 1 + pygmt/src/grdlandmask.py | 9 ++++----- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index af3fd8734d9..0bcb185fd58 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -97,7 +97,7 @@ jobs: pandas xarray netCDF4 packaging \ ${{ matrix.optional-packages }} \ dvc make pytest>=6.0 \ - pytest-cov pytest-mpl sphinx-gallery tomli + pytest-cov pytest-doctestplus pytest-mpl sphinx-gallery tomli # Show installed pkg information for postmortem diagnostic - name: List installed packages diff --git a/.github/workflows/ci_tests_dev.yaml b/.github/workflows/ci_tests_dev.yaml index b82587d39a6..3b59aeb7ff5 100644 --- a/.github/workflows/ci_tests_dev.yaml +++ b/.github/workflows/ci_tests_dev.yaml @@ -93,7 +93,7 @@ jobs: pip install --pre --prefer-binary \ numpy pandas xarray netCDF4 packaging \ dvc ipython 'pytest>=6.0' pytest-cov \ - pytest-mpl sphinx-gallery tomli + pytest-doctestplus pytest-mpl sphinx-gallery tomli # Pull baseline image data from dvc remote (DAGsHub) - name: Pull baseline image data from dvc remote diff --git a/Makefile b/Makefile index 2c1c295fc84..37339c4f77b 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,8 @@ help: @echo "" @echo " install install in editable mode" @echo " package build source and wheel distributions" - @echo " test run the test suite (including doctests) and report coverage" + @echo " test run the test suite (including some doctests) and report coverage" + @echo " fulltest run the test suite (including all doctests) and report coverage" @echo " format run black, blackdoc, docformatter and isort to automatically format the code" @echo " check run code style and quality checks (black, blackdoc, docformatter, flake8 and isort)" @echo " lint run pylint for a deeper (and slower) quality check" @@ -31,6 +32,17 @@ package: python setup.py sdist bdist_wheel test: + # Run a tmp folder to make sure the tests are run on the installed version + mkdir -p $(TESTDIR) + @echo "" + @cd $(TESTDIR); python -c "import $(PROJECT); $(PROJECT).show_versions()" + @echo "" + cd $(TESTDIR); PYGMT_USE_EXTERNAL_DISPLAY="false" pytest $(PYTEST_COV_ARGS) --doctest-plus $(PROJECT) + cp $(TESTDIR)/coverage.xml . + cp -r $(TESTDIR)/htmlcov . + rm -r $(TESTDIR) + +fulltest: # Run a tmp folder to make sure the tests are run on the installed version mkdir -p $(TESTDIR) @echo "" diff --git a/environment.yml b/environment.yml index 3fb89717c7f..96e94d0ce91 100644 --- a/environment.yml +++ b/environment.yml @@ -27,6 +27,7 @@ dependencies: - myst-parser - pylint - pytest-cov + - pytest-doctestplus - pytest-mpl - pytest>=6.0 - sphinx diff --git a/pygmt/src/grdlandmask.py b/pygmt/src/grdlandmask.py index 5e684496990..c050824dc5b 100644 --- a/pygmt/src/grdlandmask.py +++ b/pygmt/src/grdlandmask.py @@ -1,7 +1,6 @@ """ grdlandmask - Create a "wet-dry" mask grid from shoreline data base """ - from pygmt.clib import Session from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( @@ -13,6 +12,8 @@ ) from pygmt.io import load_dataarray +__doctest_skip__ = ["grdlandmask"] + @fmt_docstring @use_alias( @@ -95,12 +96,10 @@ def grdlandmask(**kwargs): Example ------- - >>> import pygmt # doctest: +SKIP + >>> import pygmt >>> # Create a landmask grid with an x-range of 125 to 130, >>> # and a y-range of 30 to 35 - >>> landmask = pygmt.grdlandmask( - ... spacing=1, region=[125, 130, 30, 35] - ... ) # doctest: +SKIP + >>> landmask = pygmt.grdlandmask(spacing=1, region=[125, 130, 30, 35]) """ if "I" not in kwargs or "R" not in kwargs: raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.")