Repository navigation
Fix the docstring examples that cannot run under doctest - #4010
Merged
Merged
Conversation
Ten modules under `mesa/` carry `>>>` examples, and eight of them fail when collected with `pytest --doctest-modules`. None of the failures are typos in prose; each is an example that cannot execute as written: - `portrayal_components.py`: continuation lines start with `>>>` instead of `...`, so doctest hands the continuation to the interpreter as a fresh statement and it raises `IndentationError`. - `meta_agents_api.py`: the `create` and `at_level` examples use `[...]` placeholders where a list of agents belongs, and discard nothing from `add_member`, whose return value then shows up as unexpected output. Both are now self-contained, with the setup taken from `docs/apis/meta_agents.md`. - `solara_viz.py` and `command_console.py`: the examples build Solara components or need a live UI callback, so they cannot run headless. They are marked `# doctest: +SKIP`, and `ModelCreator`'s dict literal continuation is fixed to `...`. `pytest --doctest-modules mesa --ignore=mesa/examples` goes from 8 failed / 2 passed to 8 passed / 2 skipped. No behaviour changes: every edit is inside a docstring. This is the first half of mesa#3864, split on request so each half can be reviewed on its own. The CI job that keeps these green is the second half. Part of mesa#3825. Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
Author
|
Half 1 of 2 from the #3864 split. The CI job that keeps these examples green is #4011, which depends on this PR. Heads-up on the red checks: they are not from this change.
It is repo-wide and not specific to any PR — |
This was referenced Oct 28, 2026
quaquel
approved these changes
Oct 28, 2026
quaquel
approved these changes
Oct 28, 2026
lahari936
added a commit
to lahari936/mesa
that referenced
this pull request
Oct 28, 2026
`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]>
quaquel
pushed a commit
that referenced
this pull request
Oct 28, 2026
`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 #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 #3864, split on request. The first half, the
docstring repairs in #4010, is merged, so this job is green on arrival.
Closes #3825.
Co-authored-by: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #3864 at @quaquel's request, so the docstring repairs and the CI job that guards them can be reviewed separately. This is half 1 of 2; the CI job follows in its own PR and depends on this one.
What is broken
Ten modules under
mesa/carry>>>examples. Eight of them fail the moment they are collected bypytest --doctest-modules, and none of the failures is a typo in prose — each is an example that cannot execute as written:visualization/components/portrayal_components.py>>>instead of..., so doctest feeds each continuation to the interpreter as a fresh statement and getsIndentationErrorexperimental/meta_agents/meta_agents_api.pycreateandat_leveluse[...]placeholders where a list of agents belongs, and never bindadd_member's return value, which then appears as unexpected outputvisualization/solara_viz.py,visualization/command_console.pyWhat this changes
portrayal_components.py— continuations fixed to....meta_agents_api.py— both examples made self-contained, with setup taken fromdocs/apis/meta_agents.mdand the[...]placeholders replaced by real agents.solara_viz.py/command_console.py— the two genuinely un-runnable examples marked# doctest: +SKIP, andModelCreator's dict literal continuation fixed to....Every edit is inside a docstring. The diff contains no changed code lines.
Verification
main@b4c2fbddpytest tests/is unaffected: 1006 passed. The one unrelated failure in that run,test_actions.py::TestOnIdle::test_suppressed_wake_is_logged_at_debug, is pre-existing test-ordering pollution — the Boltzmann example app callslog_to_stderr(..., propagate=False)at import, which mutates the globalMESAlogger and breakscaplogfor any test that runs after it. It passes whentests/experimental/test_actions.pyis run on its own.Why
mesa/examplesstays out of scopeNoted here because the follow-up CI job excludes it: it has no doctests, every
app.pybuilds a model and a renderer at import time, andst_app.pyimports streamlit, which is not a dependency.Part of #3825. Replaces the docstring half of #3864.