Skip to content

Reorganize tests into a pytest package (and fix bugs it exposed)#165

Open
derek73 wants to merge 24 commits into
masterfrom
test-reorg-pytest
Open

Reorganize tests into a pytest package (and fix bugs it exposed)#165
derek73 wants to merge 24 commits into
masterfrom
test-reorg-pytest

Conversation

@derek73

@derek73 derek73 commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

Splits the single 97KB tests.py (344 tests in one file, unittest) into a tests/ pytest package — one file per concern — and runs everything under pytest. Along the way, the migration exposed and fixed two real defects.

Test reorganization

  • 13 test classes → 13 tests/test_*.py files (one per concern); tests/base.py holds a plain HumanNameTestBase with the m() assert helper + thin assert* shims, so test bodies moved over verbatim.
  • tests/conftest.py reproduces the old dual run (every test under empty_attribute_default = '' and None) as a clean parametrized autouse fixture — reported counts are doubled (688 results from 344 methods).
  • @unittest.expectedFailure@pytest.mark.xfail (10 methods), @unittest.skipUnless(dill,…)@pytest.mark.skipif, self.assertRaisespytest.raises.
  • ConstantsCustomizationConstantsCustomizationTests so it matches python_classes = ["*Tests","*TestCase"].
  • Debug CLI moved out of tests.py into nameparser/__main__.py: python -m nameparser "Some Name".
  • Docs + CI (AGENTS.md, CONTRIBUTING.md, GitHub Actions, MANIFEST.in) updated to pytest.

Bug fixes the migration surfaced

  • initials() rendered the literal "None" for empty name parts when empty_attribute_default=None (e.g. "J. None D."). Now empty parts render as '' and a fully-empty result falls back to empty_attribute_default, consistent with the first/title accessors. (Behavior change for empty_attribute_default=None users.)
  • Test-isolation leak: several tests mutate global CONSTANTS without restoring it; the old suite only passed because unittest runs methods alphabetically. pytest runs in definition order, which exposed it. The fixture now snapshots/restores the scalar config per test, making tests order-independent.

Test Plan

  • pytest668 passed, 20 xfailed, zero failures
  • ruff check clean; mypy clean
  • Order-independence verified (reversed file order, randomized orderings)
  • sphinx-build and sdist packaging unaffected
  • python -m nameparser "Dr. Juan Q. Xavier de la Vega III" parses correctly

🤖 Generated with Claude Code

derek73 and others added 24 commits June 14, 2026 11:35
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When empty_attribute_default=None, initials() interpolated the literal
string 'None' for missing name parts (e.g. 'J. None D.' for 'John Doe').
Render empty parts as '' so str.format produces clean output, and fall
back to empty_attribute_default only for a fully-empty result, matching
the other attribute accessors (e.g. first/title). Exposed by running the
test suite with empty_attribute_default=None under isolated state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Several tests mutate scalar config on the global CONSTANTS singleton
(capitalize_name, force_mixed_case_capitalization, string_format, etc.)
without restoring it. The original suite only survived because unittest
runs methods alphabetically, so a sibling test happened to reset the
value; pytest runs in definition order, leaking state across files. The
autouse fixture now snapshots and restores these scalars around every
test, making tests order-independent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Revert an injected conditional pytest.xfail() in test_initials_simple_name
back to the verbatim original (the underlying initials() bug is now fixed).
Also remove test_custom_regex_constant, a test that was fabricated during
migration and added to both tests.py and test_constants.py; it is not part
of the original suite. tests.py restored to its original 344 methods.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant