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):

  1. Query PyPI for the latest stable pytest release.

  2. Compare against the current lower bound in pyproject.toml.

  3. If a newer version exists, update the >= specifier.

Post-update validation (overridden here):

  1. Recreate the test hatch environment to force fresh dependency resolution.

  2. Determine the highest supported Python version from tool.mafw.supported-python.

  3. Run the test suite via hatch test -py <version> --without-integration --without-slow-integration.

  4. 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

PytestTool([project_root])

Manage pytest's version lower bound in pyproject.toml.

class mafw.devtools.toolchain.tools.pytest.PytestTool(project_root: Path | None = None)[source]

Bases: ProjectTool

Manage pytest’s version lower bound in pyproject.toml.

pytest is categorized as a project tool because its version is controlled through the test optional-dependencies group in pyproject.toml. After an update, the test hatch 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. Only post_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:

  1. Force recreation of the test hatch environment so that the newly specified pytest version is resolved and installed fresh.

  2. Determine the highest supported Python version dynamically from tool.mafw.supported-python in pyproject.toml.

  3. Execute hatch test -py <version> --without-integration --without-slow-integration from the project root.

  4. 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