Skip to content

test: make Constants attribute docstring doctests actually run#195

Merged
derek73 merged 1 commit into
masterfrom
claude/vibrant-chatelet-4317b9
Jul 2, 2026
Merged

test: make Constants attribute docstring doctests actually run#195
derek73 merged 1 commit into
masterfrom
claude/vibrant-chatelet-4317b9

Conversation

@derek73

@derek73 derek73 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Constants class attributes (e.g. patronymic_name_order, middle_name_as_last) document their behavior with a bare string literal placed right after the assignment — Sphinx's attribute-docstring convention. That string never becomes a real __doc__, so doctest.DocTestFinder (and pytest's --doctest-modules, enabled via addopts) never discovers the .. doctest:: examples inside it. This let a stale example slip through CI once already (middle_name_as_last, Weak Arabic Name handling #133).
  • Add tests/test_config_attribute_docstrings.py, which parses nameparser/config/__init__.py with ast to recover those literals (the same source-level info Sphinx's autodoc reads) and runs any .. doctest:: examples found through doctest.DocTestParser/DocTestRunner, so pytest -q now actually exercises them — no separate copy of the example text to keep in sync.
  • The auto-discovery also caught a second, previously invisible docstring (empty_attribute_default) with two real bugs: a missing space after >>> and an expectation of literal None output where the REPL actually prints nothing for a None result. Both fixed.

Test plan

  • pytest -q — full suite passes (1046 passed, 4 skipped, 22 xfailed)
  • ruff check / mypy on touched files — clean
  • Verified the harness actually catches regressions: temporarily corrupted middle_name_as_last's expected doctest output, confirmed pytest -q failed with a clear diff, then reverted and confirmed green again

🤖 Generated with Claude Code

Constants class attributes document their default with a bare string
literal after the assignment (e.g. patronymic_name_order = False /
"""..."""), Sphinx's attribute-docstring convention. That string is
never a real __doc__, so doctest.DocTestFinder (and pytest's
--doctest-modules) never discovers the .. doctest:: examples inside
it -- they can silently go stale, which already happened once for
middle_name_as_last.

Add tests/test_config_attribute_docstrings.py, which parses the
source with ast to recover those literals (the same info Sphinx's
static analysis reads) and runs any doctest examples through
doctest.DocTestParser/DocTestRunner, so pytest -q now exercises them.

Discovery also caught a second dormant docstring (empty_attribute_default)
with its own bugs: a missing space after >>> and an expectation of
literal None output where the REPL prints nothing for None.
@derek73 derek73 self-assigned this Jul 2, 2026
@derek73 derek73 added this to the v1.3.0 milestone Jul 2, 2026
@derek73 derek73 merged commit 61f8c2a into master Jul 2, 2026
8 checks passed
@derek73 derek73 deleted the claude/vibrant-chatelet-4317b9 branch July 2, 2026 03:23
@derek73 derek73 added the docs Documentation fixes and updates label Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation fixes and updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant