Skip to content

Run docstring doctests in CI as their own job - #4011

Merged
quaquel merged 1 commit into
mesa:mainfrom
lahari936:doctest-ci-job
Oct 28, 2026
Merged

quaquel merged 1 commit into
mesa:mainfrom
lahari936:doctest-ci-job

Conversation

@lahari936

Copy link
Copy Markdown
Contributor

Split out of #3864 at @quaquel's request. This is half 2 of 2.

Depends on the docstring-repair PR — without it this job is red on arrival, because eight of the ten >>> examples under mesa/ cannot execute as written. Please merge that one first.

What this adds

A doctest job in build_lint.yml:

pytest --doctest-modules mesa --ignore=mesa/examples

on Python 3.14, matching the existing coverage job's setup.

It is a job of its own rather than part of the build matrix or the docs build, so a rotten docstring is reported as a rotten docstring instead of surfacing as a unit-test failure or a docs-build failure. That was @falloficaruss's suggestion on #3825.

On the three-activity framing from #3864 — build the docs, run the normal test suite, run the docstring tests — this is the third, kept out of the other two deliberately. Happy to fold it into either if you would rather have fewer jobs.

pyproject.toml

[tool.pytest.ini_options]
doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE"]

No addopts, so the normal suite is untouched. pytest tests/ --collect-only reports 1016 tests both with and without this block, and there was no other pytest config in the repo (no pytest.ini, setup.cfg or tox.ini) for it to conflict with.

Why mesa/examples is excluded

It has no doctests, every app.py builds a model and a renderer at import time, and st_app.py imports streamlit, which is not a dependency.

Verification

The exact command the job runs, locally on this branch:

pytest --doctest-modules mesa --ignore=mesa/examples -Werror -Wdefault::PendingDeprecationWarning
8 passed, 2 skipped

The workflow file parses as YAML with jobs build, coverage, doctest, examples, and uses the same actions/checkout@v7 / actions/setup-python@v7 pins as every other job in it.

Closes #3825. Replaces the CI half of #3864.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions github-actions Bot added ci Release notes label experimental Release notes label packaging Release notes label visualization labels Oct 28, 2026
@lahari936

Copy link
Copy Markdown
Contributor Author

Half 2 of 2 from the #3864 split. Depends on #4010 — eight of the ten >>> examples under mesa/ cannot execute as written, so this job is red on arrival without those repairs. #4010 wants to merge first.

On the red checks: they are a repo-wide break, not this change. pytest 9.2.0 landed pytest-dev/pytest#12697, which makes warnings raised while importing entry-point plugins go through the normal filter pipeline. Solara registers a pytest plugin by entry point, it imports websockets.legacy, and under mesa's -Werror that DeprecationWarning is now promoted to an error — so pytest exits 3 with zero tests run, in every job that passes -Werror. coverage is the only job still green, and the only one without it.

The doctest job this PR adds was caught by it too, so I have pushed the same message-scoped ignore onto it here. The underlying fix for the two pre-existing commands is a separate PR, since it is needed on main regardless of this one.

@quaquel quaquel added doctest Release note label and removed visualization experimental Release notes label labels Oct 28, 2026
Comment thread pyproject.toml
Comment on lines +94 to +97
[tool.pytest.ini_options]
# Applied to docstring examples collected via `pytest --doctest-modules`.
doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

`mesa/` carries `>>>` examples in ten modules, and nothing runs them, so
they rot silently. Add a `doctest` job to build_lint.yml that runs

    pytest --doctest-modules mesa --ignore=mesa/examples

on Python 3.14, matching the existing coverage job.

It is a separate job rather than part of the `build` matrix or the docs
build so that a rotten docstring is reported on its own, instead of
appearing as a unit-test failure or a docs-build failure. That is
@falloficaruss's suggestion on mesa#3825.

`mesa/examples` is excluded: it has no doctests, every `app.py` builds a
model and a renderer at import time, and `st_app.py` imports streamlit,
which is not a dependency.

`pyproject.toml` gains `doctest_optionflags = ["ELLIPSIS",
"NORMALIZE_WHITESPACE"]` under `[tool.pytest.ini_options]`. There is no
`addopts`, so the normal suite is untouched: `pytest tests/ --collect-only`
reports 1016 tests both with and without the block.

This is the second half of mesa#3864, split on request. The first half, the
docstring repairs in mesa#4010, is merged, so this job is green on arrival.

Closes mesa#3825.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lahari936

Copy link
Copy Markdown
Contributor Author

Thanks for merging #4010, @quaquel. Rebased this onto it, so the PR is now a single commit touching two files: the doctest job and two lines of pyproject.toml.

I had also pushed the solara/websockets -W ignore onto the new job here while CI was red this morning. I have dropped it — the matrix is green again, and that fix belongs on the two pre-existing commands rather than riding along in this PR. Filed separately so you can pick the approach.

Verified on the current main with #4010 in:

pytest --doctest-modules mesa --ignore=mesa/examples -Werror -Wdefault::PendingDeprecationWarning
8 passed, 2 skipped

@quaquel
quaquel merged commit f3bdcd6 into mesa:main Oct 28, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Release notes label doctest Release note label packaging Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repo-wide handling of docstring doctests

3 participants