Repository navigation
Conversation
|
Performance benchmarks:
|
Add repo-wide handling of docstring examples (mesa#3825): - pyproject.toml: `doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE"]` under `[tool.pytest.ini_options]`. No `addopts`, so `pytest tests/` is unchanged (834 tests collected before and after). - CI: new `doctest` job running `pytest --doctest-modules mesa --ignore=mesa/examples` so a rotten docstring is flagged on its own. `mesa/examples` is excluded because it has no doctests, every `app.py` builds a model at import time, and `st_app.py` imports streamlit which is not a dependency. - portrayal_components.py: continuation lines used `>>>` instead of `...`, which is an IndentationError under doctest. - meta_agents_api.py: `create` and `at_level` examples are now self-contained (setup copied from docs/apis/meta_agents.md); `[...]` placeholders replaced with real agents; `add_member` return value assigned so it does not produce unexpected output. - solara_viz.py / command_console.py: examples that build Solara components or need a UI callback are marked `# doctest: +SKIP`; ModelCreator's dict literal continuation fixed to `...`. Result: `pytest --doctest-modules mesa --ignore=mesa/examples` goes from 8 failed / 2 passed to 8 passed / 2 skipped. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Performance benchmarks:
|
|
This pr also updates a bunch of docstrings. Ideally, a PR is atomic, so why are these docstring changes necessary?
I think there is a third option: build the docs, run the normal test suite, run the docstring tests. Does this third option makes sense and how is it related to this PR? |
|
Thanks for looking. On the third option — yes, that makes sense, and I think it is what this PR already does, just described from the other end. Your three activities map onto three jobs:
So this PR is the third of your three, kept out of the other two deliberately. That was @falloficaruss's suggestion on #3825: a broken docstring should be reported on its own rather than mixed into a unit-test failure or a docs-build failure. Nothing about it requires doctests to be part of the docs build, which is the part I could not tell from your earlier reply. If you would rather fold them into the normal test run instead, that is a one-line change (drop the job, add On the docstring changes — fair, and you are right that the PR is doing two things. They are not drive-by edits though: without them the new job is red the moment it is added, because eight docstrings currently fail. They break down as:
If you would prefer it atomic, the natural split is:
That ordering also means PR 2 cannot be merged while anything is broken. Say the word and I will split it — I would rather do that than have you review a mixed diff. |
|
please split it in two, link to this PR but close it. I can then more quickly merge and review both PRs. |
|
Split as requested, @quaquel. Closing this in favour of the two halves:
On your third option — build the docs, run the normal test suite, run the docstring tests — #4011 is the third of those three, kept out of the other two deliberately so a rotten docstring is reported as a rotten docstring. If you would rather it folded into the docs build or the Thanks for the nudge to split; it was the right call. The docstring half is reviewable on its own in a way it was not here. |
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 #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 #3825. Co-authored-by: Claude Opus 5 <[email protected]> Co-authored-by: Jan Kwakkel <[email protected]>
`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]>
`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]>
Closes #3825.
Note
Rebased onto current
main(949dc8c5) and marked ready for review. The analysis below still holds exactly:pytest --doctest-modules mesa --ignore=mesa/examplesreports the same 8 failures on today'smainas it did when this was first written. The only change needed was following themesa/meta_agents/→mesa/experimental/meta_agents/move from the Meta-Agents Rewrite, including two doctest lines that still imported the old path.Summary
Adds repo-wide handling of
>>>docstring examples using option A from the issue (pytest --doctest-modules), as a separate CI job so a rotten docstring is flagged on its own rather than mixed into unit-test or docs-build failures — the shape @falloficaruss asked for on the issue.pyproject.toml:[tool.pytest.ini_options]withdoctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE"]. Deliberately noaddopts—pytest tests/behaves exactly as before (912 items collected before and after)..github/workflows/build_lint.yml: newdoctestjob runningpytest --doctest-modules mesa --ignore=mesa/examples -Werror -Wdefault::PendingDeprecationWarning(same-Wflags as the build job; ~20 s).mesa/visualization/components/portrayal_components.py>>>→...on continuation lines (3 examples)IndentationErrorunder doctest; the examples are otherwise correct and now execute.mesa/experimental/meta_agents/meta_agents_api.pycreatedocs/apis/meta_agents.md;[...]placeholders → real agents;_ = add_member(...)model,alice… undefined).add_memberreturns aMembershipView, which would be unexpected output.[...]is valid Python — a list containingEllipsis— so it silently created an empty group.mesa/experimental/meta_agents/meta_agents_api.pyat_levelat_level(4, root=world)one-liner with a small two-level hierarchy and asserted outputsmesa/visualization/solara_viz.py# doctest: +SKIPonSolaraViz/ModelCreator;ModelCreatordict continuation>>>→...MyModelis intentionally abstract. Skipped examples are still parsed, so the syntax fix matters.mesa/visualization/command_console.py# doctest: +SKIPset_input_textUI callback;my_modelis intentionally abstract.Result:
pytest --doctest-modules mesa --ignore=mesa/examplesgoes from 8 failed / 2 passed to 8 passed / 2 skipped.Why not B / C
tests/test_doctests.pywalker) re-implements pytest's collector (pkgutil+importlib+doctest.testmod) and reports one opaque failure instead of per-docstring items. Nothing in the current examples needs per-moduleglobsinjection.-b doctest) — ran it locally. It only sees docstrings pulled in viaautomoduleindocs/apis/*.md, so it missesmesa_signals, the one module with passing doctests today. It groups every example on a doc page into one namespace, so a single failure cascades (apis/visualizationalone is 48 examples). And via:inherited-members:onPriority(IntEnum)it ends up testing CPython'sint.bit_lengthdocstring. It also needs the[docs]extras, notebook execution off, andPYTHONUTF8=1on Windows. No coverage gain over A.Why
--ignore=mesa/examplesmesa/exampleshas zero doctests; importing it takes ~27 s because everyapp.pyinstantiates a model and renderer at import time; and twost_app.pyfiles hard-fail onModuleNotFoundError: streamlit, which isn't a dependency anywhere. Examples are already covered bytests/examples/. If a doctest is added to an example later, dropping the--ignoreis a one-line change.Testing
Against current
main:The one full-suite failure is
test_suppressed_wake_is_logged_at_debug, the pre-existing logging-propagation bug in #3935 (fixed by #3938 once it lands), unrelated to this PR.pre-commitis clean.Open points
tests/experimental/test_mesa_signals.py::test_signal_type_docstringsis left in place. It is now redundant with the CI job, but removing it felt out of scope here.[tool.pytest.ini_options]section makespyproject.tomlpytest's inifile, pinning rootdir to the repo root. Every current invocation already runs from there, so there is no observable change.CONTRIBUTING.mdif wanted.