Repository navigation
Fix package doctests and stop testpaths from hiding them - #4
Merged
Merged
Conversation
`[tool.pytest.ini_options] testpaths = ["tests"]` scoped pytest collection away from the package, so none of the docstring examples under `doodad/` ever ran -- locally or in CI. Two of them were failing the whole time: - `extract_names_from_code(os.path.join)` raised `OSError: could not get source code` from `inspect.getsource`. - `find_names(os.path.join)` returned `[]` instead of the documented names -- a silent wrong answer, because `dflt_value_normalizer` swallows the `OSError` and falls through to the mapping branch. Root cause is not in doodad: `os.path` is frozen into the interpreter from CPython 3.11 on (`posixpath.__spec__` reports `origin='frozen'`), so it has no retrievable source. Both 3.10 and 3.12 are in the CI matrix, so the examples were version-dependent as written. Changes: - Re-target both examples at a function from doodad's own source tree and assert name membership rather than an exact ordered list, so they neither depend on interpreter internals nor re-break on a signature change. Also corrects a stale lead-in sentence that described the wrong example. - Widen `testpaths` to `["doodad", "tests"]`. The CI runner invokes pytest with `--doctest-modules` and no path argument, so `testpaths` alone decided whether the package was doctested at all. Collected items under the CI invocation go from 1 to 10. - Add `tests/test_doctests.py`, which runs every module's examples with the exact flag set CI forces. CI overrides `doctest_optionflags` and thereby drops `NORMALIZE_WHITESPACE`, so a whitespace-sensitive example can pass a plain local run and still fail CI; running from `tests/` -- the one directory this repo has always collected -- closes that gap and keeps the examples from being hidden again by a future `testpaths` change. - Move `from contextlib import suppress` to the import block. It sat at the bottom of the module while `dflt_value_normalizer` (defined at the top) uses it -- safe only because nothing calls that function during import. No public name, signature, default or return value changes; the edits are docstrings, a pytest config key, and an import relocation within the module. Claude-Session: https://claude.ai/code/session_01L1aQPB34n7PU7jmbztSjBe
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.
Summary
Fixes i2mint/doodad#3 — 3 package doctests were silently disabled because
[tool.pytest.ini_options] testpaths = ["tests"]scoped collection totests/only, so nothing underdoodad/was ever doctested, locally or in CI.doodad/find_names.py: the two doctests that usedos.path.join(a C-accelerated/frozen builtin on this interpreter) as aninspect.getsource-able example are replaced with a self-contained example (yield_names_from_mapping) that doesn't depend on interpreter internals.pyproject.toml:testpathswidened to["doodad", "tests"]so the package's own doctests are actually collected.tests/test_doctests.py: new guard that walks every importable module underdoodadand runs its doctests with the exactdoctest_optionflagsthe CI runner forces (ELLIPSIS IGNORE_EXCEPTION_DETAIL, which dropsNORMALIZE_WHITESPACE), so a whitespace-sensitive doctest can't pass locally and silently fail in CI again.Verification
Reproduced the pre-fix failure on this box:
python -m pytest doodad --doctest-modules -o doctest_optionflags='ELLIPSIS IGNORE_EXCEPTION_DETAIL' -qonmaster(1f13f92) fails 2 of the reported doctests withOSError: could not get source code/ wrong expected output (the third failure noted in the issue did not reproduce on this interpreter/Python 3.12.14, consistent with it being interpreter-dependent — theos.path.join-based examples are exactly the kind of thing that varies across builds).wads ci-localon this branch: PASSED — ruff format + lint, pytest (py3.10 and py3.12, including the new doctest collection: 10 passed), build. No rebase was needed; the branch already sits directly on currentmaster.Closes #3
🤖 Generated with Claude Code