Skip to content

Fix package doctests and stop testpaths from hiding them - #4

Merged
thorwhalen merged 1 commit into
masterfrom
fix/unhide-package-doctests
Sep 22, 2026
Merged

thorwhalen merged 1 commit into
masterfrom
fix/unhide-package-doctests

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

Summary

Fixes i2mint/doodad#3 — 3 package doctests were silently disabled because [tool.pytest.ini_options] testpaths = ["tests"] scoped collection to tests/ only, so nothing under doodad/ was ever doctested, locally or in CI.

  • doodad/find_names.py: the two doctests that used os.path.join (a C-accelerated/frozen builtin on this interpreter) as an inspect.getsource-able example are replaced with a self-contained example (yield_names_from_mapping) that doesn't depend on interpreter internals.
  • pyproject.toml: testpaths widened to ["doodad", "tests"] so the package's own doctests are actually collected.
  • tests/test_doctests.py: new guard that walks every importable module under doodad and runs its doctests with the exact doctest_optionflags the CI runner forces (ELLIPSIS IGNORE_EXCEPTION_DETAIL, which drops NORMALIZE_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' -q on master (1f13f92) fails 2 of the reported doctests with OSError: 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 — the os.path.join-based examples are exactly the kind of thing that varies across builds).

wads ci-local on 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 current master.

Closes #3

🤖 Generated with Claude Code

`[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
@thorwhalen
thorwhalen merged commit 9741e9c into master Sep 22, 2026
7 checks passed
@thorwhalen
thorwhalen deleted the fix/unhide-package-doctests branch September 22, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 package doctests fail, hidden by testpaths

1 participant