-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use pytest-doctestplus to skip some inline doctests #1790
Conversation
Ping @meghanrjones @weiji14 @willschlitzer @michaelgrund for comments on the new doctest method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great find! Should have found this earlier 😆 I have one suggestion in regard to Problem 3 below.
pyproject.toml
Outdated
@@ -3,7 +3,7 @@ omit = ["*/tests/*", "*pygmt/__init__.py"] | |||
|
|||
[tool.pytest.ini_options] | |||
minversion = "6.0" | |||
addopts = "--verbose --durations=0 --durations-min=0.2 --doctest-modules --mpl --mpl-results-path=results" | |||
addopts = "--verbose --durations=0 --durations-min=0.2 --doctest-plus --mpl --mpl-results-path=results" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For problem 3, there is still no easy way, but I think it's possible to comment the doctest_skip line, run the tests, and then revert the changes.
Actually, from reading the doctest-plus docs (https://github.com/astropy/pytest-doctestplus/tree/v0.12.0#setup-and-configuration), it says:
Using pytest's built-in
--doctest-modules
option will override the behavior of this plugin, even ifdoctest_plus = enabled in setup.cfg
, and will cause the default doctest plugin to be used. However, if for some reason both--doctest-modules
and--doctest-plus
are given, thepytest-doctestplus
plugin will be used, regardless of the contents ofsetup.cfg
.
So maybe we just need to edit the Makefile, and have have a make doctest
command that uses --doctest-modules
instead of doctest-plus
to run all of these doctests? Could also setup a CI to have it run weekly if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. I removed the --doctest-plus
option from pyproject.toml
, and added it to make test
command. I also the make fulltest
target with the --doctest-modules
option (I think the make doctest
command is misleading).
Now, running make test
collects 541 tests, and running make fulltest
collects 542 tests. The extra one in make fulltest
comes is the grdlandmask
doctest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!
I think the contributors guide should provide information about adding inline examples/doctests including how to skip tests using __doctest_skip__
and run the full tests using make fulltest
or pytest pygmt/src/<module>.py --doctest-modules
, but this could be handled in a separate PR.
I added the Now here are three different ways to run tests:
|
…ols#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
Description of proposed changes
We're adding more and more inline code examples in function docstrings as tracked in issue #1686. We don't want these new doctests slow down our CI, so we skip these doctests using the
# doctest: +SKIP
directive. Here is an example doctest ingrdlandmask
:As you can see, there are many downsides for this kind of doctests:
# doctest: +SKIP
only works for one single line, so we have to add# doctest: +SKIP
many times# doctest: +SKIP
has 18 characters. So even a short code likelandmask = pygmt.grdlandmask(spacing=1, region=[125, 130, 30, 35])
must be split into multiple linesIn this PR, the
pytest-doctestplus
plugin is used to solve the problems above. For each module, we just need to define an internal variable__doctest_skip__
, which contains a list of functions/classes whose tests should be skipped.See the changes in
pygmt/src/grdlandmask.py
as an example and also the official documentation of pytest-doctestplus.As you can see, it solves the problems 1 and 2 above.
For problem 3, there is still no easy way, but I think it's possible to comment the
__doctest_skip__
line, run the tests, and then revert the changes.