Skip to content

test: adopt -Werror in unit tests - #776

Open
tonyandrewmeyer wants to merge 1 commit into
canonical:mainfrom
tonyandrewmeyer:w-error-12factor
Open

test: adopt -Werror in unit tests#776
tonyandrewmeyer wants to merge 1 commit into
canonical:mainfrom
tonyandrewmeyer:w-error-12factor

Conversation

@tonyandrewmeyer

Copy link
Copy Markdown
Contributor

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 vendored loki_k8s lib and from paas_charm: upstream canonical/loki-k8s-operator and canonical/paas-charm.
    • The `dict` method is deprecated; use `model_dump` instead, from paas_charm.charm_state calling pydantic's deprecated BaseModel.dict(): upstream canonical/paas-charm.
  • tox.ini: 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 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 -Werror turns 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

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
tonyandrewmeyer requested a review from a team as a code owner August 17, 2026 06:05
@tonyandrewmeyer
tonyandrewmeyer requested review from f-atwi and minulo and removed request for a team August 17, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant