From 8075d7ea22001da34fe8c54fde9c18ae3fd29bea Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Mon, 17 Aug 2026 18:01:40 +1200 Subject: [PATCH] test: adopt -Werror in unit tests Promote warnings to errors in the unit suite so deprecations and resource leaks fail the tests rather than accumulating in the log. Three warnings surface, all from third-party code -- the charm's own code raises none: - JujuVersion.from_environ() is deprecated, raised by the vendored loki_k8s charm lib and by paas_charm - pydantic's BaseModel.dict(), called by paas_charm.charm_state Each is ignored by message, so a new warning of a different shape from the same module still fails. The fixes belong upstream in canonical/loki-k8s-operator and canonical/paas-charm. filterwarnings in pyproject.toml applies to every pytest run in the repo, so the integration env overrides it back to empty: those runs raise SSL and websocket warnings from juju that are not ours to fix. Unit suite: 12 passed, 0 warnings. Co-Authored-By: Claude Opus 5 (1M context) --- .../artifacts/werror-unit-tests.yaml | 15 +++++++++++++++ pyproject.toml | 14 ++++++++++++++ tox.ini | 1 + 3 files changed, 30 insertions(+) create mode 100644 docs/release-notes/artifacts/werror-unit-tests.yaml diff --git a/docs/release-notes/artifacts/werror-unit-tests.yaml b/docs/release-notes/artifacts/werror-unit-tests.yaml new file mode 100644 index 00000000..e5a92006 --- /dev/null +++ b/docs/release-notes/artifacts/werror-unit-tests.yaml @@ -0,0 +1,15 @@ +# --- Release notes artifact ---- + +schema_version: 1 +changes: + - title: Run the unit tests with warnings promoted to errors + author: tonyandrewmeyer + type: chore + description: | + The unit tests now run with `filterwarnings = ["error", ...]`, so a deprecation or resource leak fails the suite instead of scrolling past in the log. Three third-party warnings are ignored by message; the charm's own code raises none. Integration tests are unaffected. + urls: + pr: https://github.com/canonical/indico-operator/pull/776 + related_doc: + related_issue: + visibility: internal + highlight: false diff --git a/pyproject.toml b/pyproject.toml index be30603f..16d40bc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,20 @@ pythonpath = [ "lib", "src", ] +# Turn warnings into errors so deprecations and resource leaks fail the unit +# suite rather than accumulating unnoticed. Each ignore below is anchored to a +# specific message and is for third-party code; the charm's own code raises +# none. The integration env opts out (see tox.ini) because the warnings there +# come from juju/websockets and are not ours to fix. +filterwarnings = [ + "error", + # Raised by the vendored loki_k8s charm lib and by paas_charm; the fixes + # belong upstream in canonical/loki-k8s-operator and canonical/paas-charm. + "ignore:JujuVersion.from_environ\\(\\) is deprecated:DeprecationWarning", + # paas_charm.charm_state calls pydantic's deprecated BaseModel.dict(); + # the fix belongs upstream in canonical/paas-charm. + "ignore:The `dict` method is deprecated; use `model_dump` instead:DeprecationWarning", +] # Linting tools configuration [tool.ruff] diff --git a/tox.ini b/tox.ini index abd4c8a0..b499087d 100644 --- a/tox.ini +++ b/tox.ini @@ -91,5 +91,6 @@ commands = -s \ --tb native \ --log-cli-level=INFO \ + --override-ini=filterwarnings= \ {posargs} \ {[vars]tests_path}/integration