diff --git a/testing/pyproject.toml b/testing/pyproject.toml index b28b9795fe..0cdfa0952a 100644 --- a/testing/pyproject.toml +++ b/testing/pyproject.toml @@ -38,5 +38,11 @@ classifiers = [ "Homepage" = "https://github.com/canonical/operator" "Bug Tracker" = "https://github.com/canonical/operator/issues" +[dependency-groups] +unit = [ + "ops-tracing", + "pytest~=9.0", +] + [tool.hatch.build.targets.wheel] packages = ["src/scenario"] # Hatch looks for 'ops_scenario' by default. diff --git a/testing/tests/benchmark/test_testing.py b/testing/tests/benchmark/test_testing.py index 6dd5f60285..388ed8148d 100644 --- a/testing/tests/benchmark/test_testing.py +++ b/testing/tests/benchmark/test_testing.py @@ -25,6 +25,8 @@ import ops from ops import testing +pytest.importorskip('pytest_benchmark') # Provides the 'benchmark' fixture. + @pytest.fixture def benchmark_charm(): diff --git a/testing/tests/test_e2e/conftest.py b/testing/tests/test_e2e/conftest.py index 26fb185651..9c26c39fef 100644 --- a/testing/tests/test_e2e/conftest.py +++ b/testing/tests/test_e2e/conftest.py @@ -3,6 +3,7 @@ from __future__ import annotations +import pathlib from collections.abc import Generator from typing import Any @@ -19,8 +20,8 @@ def secrets_context(secrets_charm_meta: dict[str, Any]): @pytest.fixture -def secrets_charm_meta(pytestconfig: pytest.Config) -> Generator[dict[str, Any]]: +def secrets_charm_meta() -> Generator[dict[str, Any]]: """Metadata for the secret test charm.""" - return yaml.safe_load( - (pytestconfig.rootpath / 'test/charms/test_secrets/charmcraft.yaml').read_text() - ) + # The repository root, so the path doesn't depend on pytest's rootdir. + root = pathlib.Path(__file__).parents[3] + return yaml.safe_load((root / 'test/charms/test_secrets/charmcraft.yaml').read_text()) diff --git a/testing/tests/test_e2e/test_trace_data.py b/testing/tests/test_e2e/test_trace_data.py index 9b4819c967..83b92bbb1c 100644 --- a/testing/tests/test_e2e/test_trace_data.py +++ b/testing/tests/test_e2e/test_trace_data.py @@ -3,10 +3,13 @@ from __future__ import annotations +import pytest from scenario import Context, State import ops +pytest.importorskip('ops_tracing') + META = { 'name': 'traced_charm', 'requires': {'charm-tracing': {'interface': 'tracing', 'limit': 1}}, diff --git a/testing/tox.ini b/testing/tox.ini new file mode 100644 index 0000000000..467c816009 --- /dev/null +++ b/testing/tox.ini @@ -0,0 +1,23 @@ +[tox] +requires = tox>=4.2 +env_list = unit +skip_missing_interpreters = true + +[testenv] +runner = uv-venv-lock-runner +setenv = + PY_COLORS=1 +passenv = + HOME + PATH + SCENARIO_SKIP_CONSISTENCY_CHECKS + SCENARIO_BARE_CHARM_ERRORS + +[testenv:py{3.10,3.12,3.14}-unit] +# runner must be re-specified here due to tox environment inheritance shenanigans +runner = uv-venv-lock-runner +base = unit + +[testenv:unit] +dependency_groups = unit +commands = pytest {posargs} diff --git a/tracing/pyproject.toml b/tracing/pyproject.toml index 0945421c1d..92c36432ca 100644 --- a/tracing/pyproject.toml +++ b/tracing/pyproject.toml @@ -49,7 +49,7 @@ lint = [ "pyright~=1.1", ] unit = [ - "ops[testing]", + "ops-scenario", "pytest~=9.0", ] diff --git a/uv.lock b/uv.lock index 9cdb739a59..9a19d31687 100644 --- a/uv.lock +++ b/uv.lock @@ -910,6 +910,12 @@ dependencies = [ { name = "typing-extensions" }, ] +[package.dev-dependencies] +unit = [ + { name = "ops-tracing" }, + { name = "pytest" }, +] + [package.metadata] requires-dist = [ { name = "ops", editable = "." }, @@ -917,6 +923,12 @@ requires-dist = [ { name = "typing-extensions", specifier = ">=4.9.0" }, ] +[package.metadata.requires-dev] +unit = [ + { name = "ops-tracing", editable = "tracing" }, + { name = "pytest", specifier = "~=9.0" }, +] + [[package]] name = "ops-tracing" version = "3.10.0.dev0" @@ -935,7 +947,7 @@ lint = [ { name = "ruff" }, ] unit = [ - { name = "ops", extra = ["testing"] }, + { name = "ops-scenario" }, { name = "pytest" }, ] @@ -954,7 +966,7 @@ lint = [ { name = "ruff", specifier = "==0.17.2" }, ] unit = [ - { name = "ops", extras = ["testing"], editable = "." }, + { name = "ops-scenario", editable = "testing" }, { name = "pytest", specifier = "~=9.0" }, ]