Skip to content

test: adopt -Werror in unit tests#771

Open
tonyandrewmeyer wants to merge 3 commits into
canonical:mainfrom
tonyandrewmeyer:w-error
Open

test: adopt -Werror in unit tests#771
tonyandrewmeyer wants to merge 3 commits into
canonical:mainfrom
tonyandrewmeyer:w-error

Conversation

@tonyandrewmeyer

@tonyandrewmeyer tonyandrewmeyer commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Applicable spec: N/A

Overview

Promote warnings to errors in the unit suite, and clear the one production deprecation it surfaces so the suite is green under it as-pinned.

  • src/charm.py: _has_secrets() switches from the deprecated JujuVersion.from_environ() to self.model.juju_version.has_secrets.
  • pyproject.toml: adopt -Werror, with four narrow, message-anchored, individually justified ignores:
    • Harness is deprecated.
    • JujuVersion.from_environ() from the vendored data_platform_libs lib: module-scoped, upstream canonical/data-platform-libs.
    • Implicitly cleaning up <TemporaryDirectory> Harness teardown leak: temporary, drop on the next ops 2.23 release that backports the fix or when this charm moves to ops >= 3.8.
    • unclosed file …yaml scenario.Context teardown leak on the charm metadata files, same temporary situation.

Rationale

Without -Werror the suite was carrying 97 warnings, including a real production deprecation in _has_secrets(). Flipping turns those into a CI signal so future deprecations and resource leaks fail the suite rather than piling up quietly. Context: discourse post.

Juju Events Changes

None.

Module Changes

_has_secrets() reads the juju version from self.model.juju_version instead of calling the deprecated JujuVersion.from_environ(); same observable behaviour.

Library Changes

None.

Checklist

tonyandrewmeyer and others added 3 commits June 30, 2026 23:50
…from_environ

JujuVersion.from_environ() was deprecated in favour of accessing the
juju version through the model. The unit tests that mocked it via
@patch.object(ops.JujuVersion, "from_environ") are updated to patch
ops.model.Model.juju_version (PropertyMock) so they still control
whether secrets are reported as supported.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Treat warnings as errors in the unit suite via filterwarnings = ["error", ...]
in [tool.pytest.ini_options], with narrow ignores for the warnings the
upstream Harness-style suite intentionally still trips:

- `Harness is deprecated` — the unit_harness/ suite intentionally stays
  on Harness, perpetual ignore.
- `JujuVersion.from_environ() is deprecated` from the vendored
  data_platform_libs lib — upstream canonical/data-platform-libs.
- `Implicitly cleaning up <TemporaryDirectory>` — Harness tempdir
  teardown leak (operator#2506/#2507); marked TEMPORARY, drop on next
  ops 2.23 release backporting the fix, or when this charm bumps to
  ops >= 3.8.
- `unclosed file …yaml` — scenario.Context teardown leak on the charm
  metadata files (same operator#2506/#2507 class); same TEMPORARY note.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Integration tests surface SSL/websocket unraisable exception warnings
from juju/websockets that are out of our control. Override filterwarnings
to empty for the integration env so -Werror applies to unit tests only.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tonyandrewmeyer tonyandrewmeyer marked this pull request as ready for review June 30, 2026 22:05
@tonyandrewmeyer tonyandrewmeyer requested a review from a team as a code owner June 30, 2026 22:05
@tonyandrewmeyer tonyandrewmeyer requested review from minulo and yanksyoon and removed request for a team June 30, 2026 22: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