Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Dec 20, 2025

Some doctests are mainly intended to demonstrate the usage of functions or methods rather than for actual testing. Such tests can be skipped using the __doctest_skip__ directive (initially introduced in PR #1790). However, it's easy to forget to add this directive to some methods or functions.

To help identify these cases, I asked ChatGPT to write a simple Python script that finds modules containing doctests but missing the __doctest_skip__ directive. It works, but still flags modules that shouldn't be reported. Thus, we can't add it to our CI workflow, but we can sometimes run it and review the report manually.

import doctest
import pkgutil
import pygmt

TARGETS = ("pygmt.src", "pygmt.datasets", "pygmt.params")

missing = []
for modinfo in pkgutil.walk_packages(pygmt.__path__, pygmt.__name__ + "."):
    name = modinfo.name
    if not name.startswith(TARGETS):
        continue

    module = __import__(name, fromlist=["*"])

    # Detect whether the module actually contains doctests
    finder = doctest.DocTestFinder()
    tests = finder.find(module)
    if not any(test.examples for test in tests):
        continue

    if "__doctest_skip__" not in module.__dict__:
        missing.append(name)

if missing:
    print(
        "__doctest_skip__ missing in modules that contain doctests:\n"
        + "\n".join(f"  - {m}" for m in missing)
    )

This PR adds the missing __doctest_skip__ directives to the appropriate methods and functions.

@seisman seisman added this to the 0.18.0 milestone Dec 20, 2025
@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog final review call This PR requires final review and approval from a second reviewer labels Dec 20, 2025
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Dec 20, 2025
@seisman seisman merged commit 3f7c24d into main Dec 20, 2025
23 checks passed
@seisman seisman deleted the doctest_skip branch December 20, 2025 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants