mafw.devtools.toolchain.tools.pytest
Concrete ProjectTool implementation for pytest.
pytest is a project tool whose version lower bound is declared in
project.optional-dependencies.test. This module manages the >=
specifier for pytest and validates updates by running the full test suite
via hatch.
Update logic (inherited from ProjectTool):
Query PyPI for the latest stable pytest release.
Compare against the current lower bound in pyproject.toml.
If a newer version exists, update the
>=specifier.
Post-update validation (overridden here):
Recreate the
testhatch environment to force fresh dependency resolution.Determine the highest supported Python version from
tool.mafw.supported-python.Run the test suite via
hatch test -py <version> --without-integration --without-slow-integration.If the test suite fails, revert pyproject.toml to its previous content.
The revert pattern uses _revert()
which restores the raw pyproject.toml content saved before the update.
Classes
|
Manage pytest's version lower bound in pyproject.toml. |
- class mafw.devtools.toolchain.tools.pytest.PytestTool(project_root: Path | None = None)[source]
Bases:
ProjectToolManage pytest’s version lower bound in pyproject.toml.
pytest is categorized as a project tool because its version is controlled through the
testoptional-dependencies group inpyproject.toml. After an update, thetesthatch environment is recreated and the full test suite is executed at the highest supported Python version to validate compatibility. If the tests fail, pyproject.toml is reverted to its pre-update state.All standard behaviour (version detection, update, verify, bootstrap) is provided by
ProjectTool. Onlypost_update()is overridden to run the test suite.- Parameters:
project_root (Path | None) – Path to the project root directory containing
pyproject.toml. Defaults to the current working directory.
- post_update() None[source]
Recreate the test environment, then run the test suite; revert on failure.
Steps:
Force recreation of the
testhatch environment so that the newly specified pytest version is resolved and installed fresh.Determine the highest supported Python version dynamically from
tool.mafw.supported-pythonin pyproject.toml.Execute
hatch test -py <version> --without-integration --without-slow-integrationfrom the project root.If the test suite fails (non-zero exit code), attempt to extract the conflicting package name via
_parse_resolution_failure, revert pyproject.toml, and raise a descriptive error.
- Raises:
DevtoolsError – If the test suite fails after the update, or if environment recreation fails due to a resolution conflict.
- property env_name: str
Hatch environment where pytest is validated.
- Returns:
"hatch-test"- Return type:
str
- property package_name: str
PyPI package name.
- Returns:
"pytest"- Return type:
str
- property section_path: str
TOML section path where pytest is declared.
- Returns:
"project.optional-dependencies.test"- Return type:
str