test: adopt -Werror in unit tests - #776
Open
tonyandrewmeyer wants to merge 1 commit into
Open
Conversation
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) <noreply@anthropic.com>
tonyandrewmeyer
requested review from
f-atwi and
minulo
and removed request for
a team
August 17, 2026 06:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applicable spec: N/A
Overview
Promote warnings to errors in the unit suite, so a deprecation or a resource leak fails the tests rather than scrolling past in the log.
pyproject.toml: adopt-Werror, with two narrow, message-anchored, individually justified ignores covering the three warnings the suite raises. Both are third-party — the charm's own code raises none:JujuVersion.from_environ() is deprecated, from the vendoredloki_k8slib and frompaas_charm: upstreamcanonical/loki-k8s-operatorandcanonical/paas-charm.The `dict` method is deprecated; use `model_dump` instead, frompaas_charm.charm_statecalling pydantic's deprecatedBaseModel.dict(): upstreamcanonical/paas-charm.tox.ini:filterwarningsinpyproject.tomlapplies 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 this charm's to fix, and promoting them would be scope creep.Each ignore is anchored to a message rather than a module or a category, so a different warning from the same third-party code still fails the suite.
Unit suite after the change: 12 passed, 0 warnings.
Rationale
Flipping the unit tests to
-Werrorturns deprecations and resource leaks into a CI signal, so they surface while they are still cheap to fix rather than piling up until something breaks. The 12-factor charm is a good place to start from — its own code is already clean, so this is config only. Context: discourse post.This replaces #771, which predated the 12-factor rewrite in #772 and no longer applies to the current tree.
Juju Events Changes
None.
Module Changes
None.
Library Changes
None.
Checklist
The documentation for charmhub is updateddocs/release-notes/artifacts. If this PR does not require a change artifact, the PR has been tagged withno-release-note.urgent,trivial,complex). I cannot add tags.The changelog is updated with user-relevant changes in the format of keep a changelog v1.1.0