Skip to content

♻️ refactor: modernize for Python 3.10+ and public pytest APIs#202

Merged
gaborbernat merged 2 commits intopytest-dev:mainfrom
gaborbernat:modernize
Feb 11, 2026
Merged

♻️ refactor: modernize for Python 3.10+ and public pytest APIs#202
gaborbernat merged 2 commits intopytest-dev:mainfrom
gaborbernat:modernize

Conversation

@gaborbernat
Copy link
Collaborator

The project declares requires-python = ">=3.10" but carried runtime version guards and relied on private _pytest internals that have public replacements. This cleans up those legacy patterns to reduce coupling to pytest internals and remove dead code.

The Formatter dataclass used a sys.version_info check to conditionally pass slots and kw_only — unnecessary since 3.10 is the floor. Fixture signatures used _pytest.fixtures.SubRequest and _pytest.terminal.TerminalReporter when pytest.FixtureRequest and pytest.TerminalReporter are the public equivalents. The create_pretty_printer fixture constructed a Formatter that was immediately discarded. ♻️ All of these are cleaned up.

Tests migrated from the legacy pytest.Testdir (backed by py.path.local) to pytest.Pytester (backed by pathlib.Path), removing the Path(str(testdir.tmpdir)) workaround. 🔧 Build tooling moves from tox.ini to tox.toml and the type checker switches from mypy to ty.

The project declares requires-python >= 3.10 but had runtime version
checks and used deprecated/private pytest APIs. This cleans that up.

Drop sys.version_info guard on Formatter dataclass since slots and
kw_only are always available. Replace private _pytest.fixtures.SubRequest
with public pytest.FixtureRequest. Remove unused Formatter construction
in create_pretty_printer fixture.

Migrate tests from legacy pytest.Testdir (py.path-based) to modern
pytest.Pytester (pathlib-based), eliminating the Path(str(tmpdir))
workaround.

Switch type checker from mypy to ty and migrate tox.ini to tox.toml.
Suppress RUF067 since code in __init__ modules is intentional here.
CaptureManager remains on _pytest.capture as pytest does not expose it.
@gaborbernat gaborbernat merged commit ee47d2d into pytest-dev:main Feb 11, 2026
8 of 9 checks passed
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