diff --git a/craft_cli/pytest_plugin.py b/craft_cli/pytest_plugin.py index 46446266..9faaed20 100644 --- a/craft_cli/pytest_plugin.py +++ b/craft_cli/pytest_plugin.py @@ -25,7 +25,12 @@ from typing import TYPE_CHECKING, Any, Literal from unittest.mock import call -import pytest +try: + import pytest +except ImportError as err: + raise ImportError( + "craft-cli's pytest plugin requires pytest; install it with 'craft-cli[pytest]'" + ) from err from typing_extensions import Self from craft_cli import messages, printer diff --git a/docs/changelog.rst b/docs/changelog.rst index 5d1cbb8b..4ee4cae3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -11,10 +11,17 @@ included in each version. 3.4.2 (unreleased) ------------------ +New features: + +- Add an optional ``pytest`` dependency group (``craft-cli[pytest]``) to track + the minimum pytest version required by the ``emitter`` test plugin. + Bug fixes: - The ``emitter`` test fixture now rejects a negative ``advance`` amount, matching the behavior of the real progress bar. +- The ``emitter`` test plugin now reports a clear, actionable error message + when pytest is not installed, instead of a bare ``ModuleNotFoundError``. .. _release-3.4.1: diff --git a/pyproject.toml b/pyproject.toml index 077e008b..f2b4e36e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,9 @@ Issues = "https://github.com/canonical/craft-cli/issues" [project.entry-points.pytest11] emitter = "craft_cli.pytest_plugin" +[project.optional-dependencies] +pytest = ["pytest>=8.4"] + [dependency-groups] dev = [ "coverage[toml]==7.16.2", diff --git a/uv.lock b/uv.lock index c3706b84..eb750c73 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 5 +revision = 3 requires-python = ">=3.10" resolution-markers = [ "python_full_version >= '3.15'", @@ -582,6 +582,11 @@ dependencies = [ { name = "typing-extensions" }, ] +[package.optional-dependencies] +pytest = [ + { name = "pytest" }, +] + [package.dev-dependencies] dev = [ { name = "coverage", extra = ["toml"] }, @@ -617,9 +622,11 @@ types = [ requires-dist = [ { name = "jinja2", specifier = ">=3.1.5" }, { name = "platformdirs" }, + { name = "pytest", marker = "extra == 'pytest'", specifier = ">=8.4" }, { name = "pywin32", marker = "sys_platform == 'win32'" }, { name = "typing-extensions" }, ] +provides-extras = ["pytest"] [package.metadata.requires-dev] dev = [