Repository navigation
Conversation
Run the unit suites of the four charms with filterwarnings = ["error"] so a deprecation, a leaked file handle or a misused library fails the test instead of scrolling past in the log. Charm Tech is making this the Charmcraft default and asked existing charms to opt in. Each integration env opts out with --override-ini=filterwarnings=. Turning it on surfaced warnings that are fixed here: - haproxy-operator's TLS test fixtures called the deprecated generate_private_key(), generate_csr(), generate_ca() and generate_certificate() helpers; they now use the replacements the warnings name. The CA is now signed with the key the fixture returns. - The legacy mock_requirer_charm fixture never cleaned up its Harness, so its temporary directory was reclaimed by the garbage collector with a ResourceWarning that failed whichever test was running. - haproxy-route-policy's WhiteNoise middleware warned about the missing static directory in tests; the test settings now enable autorefresh. Left as narrow ignores: ops' Harness deprecation, scoped to the three legacy Harness test modules, and JujuVersion.from_environ() from the vendored data_platform_libs lib in haproxy-route-policy-operator. haproxy-route-policy runs Django's test runner rather than pytest, so its unit envs use python -W error instead.
Comment on lines
+117
to
+121
| # Turn warnings into errors so deprecations and resource leaks fail the unit | ||
| # suite rather than accumulating unnoticed. The charm's own code and | ||
| # tests raise none. The integration env opts | ||
| # out (see tox.toml) because any warnings there come from the deployment | ||
| # tooling and are not this charm's to fix. |
Collaborator
There was a problem hiding this comment.
@copilot shorten this comment to just "promote warnings to test failures". Apply it every other places
Contributor
There was a problem hiding this comment.
Updated all four pytest configuration comments to “promote warnings to test failures” in commit d07fabd.
Co-authored-by: Thanhphan1147 <42444001+Thanhphan1147@users.noreply.github.com>
Comment on lines
+132
to
+134
| # pyproject.toml promotes warnings to errors for the unit tests; the | ||
| # integration suite runs against real deployment tooling whose warnings | ||
| # are not this charm's to fix, so it keeps pytest's default handling. |
Collaborator
There was a problem hiding this comment.
@copilot shorten this to "Don't promote warnings for integration tests"
Contributor
There was a problem hiding this comment.
Updated the integration warning comments in all four tox.toml files in commit 2a6d06c.
Co-authored-by: Thanhphan1147 <42444001+Thanhphan1147@users.noreply.github.com>
Thanhphan1147
approved these changes
Oct 20, 2026
Collaborator
|
LGTM, thanks! I asked copilot to shorten some of the comments to be more concise. |
This branch has not been deployed
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.
Summary
Implemented test enhancement per this post.
What this PR does
Runs the unit tests of every charm in the monorepo with pytest's
filterwarnings = ["error"], so a deprecation, a leaked file handle or a misused library fails the test instead of scrolling past in the log. canonical/indico-operator#776 is the same change on indico.Configuration
haproxy-operator,haproxy-route-policy-operator,haproxy-spoe-auth-operatorandhaproxy-ddos-protection-configurator:pyproject.tomlgainsfilterwarningswith"error"first. Eachtox.tomlintegration env passes--override-ini=filterwarnings=, so warnings from the deployment tooling cannot break those runs.haproxy-route-policy-operatorignores one third-party warning by message:JujuVersion.from_environ() is deprecated, raised by the vendoreddata_platform_libslib, which still makes that call at its newest patch.haproxy-operator/tests/unit/legacyignore ops'Harness is deprecatedwarning through a module-levelpytestmark. Harness used anywhere else still fails.haproxy-route-policyruns Django's test runner rather than pytest, so itsunitandunit_authenvs run underpython -W errorinstead.Fixes for warnings that were ours
haproxy-operator/tests/unit/conftest.py: the TLS fixtures called the deprecatedgenerate_private_key(),generate_csr(),generate_ca()andgenerate_certificate()helpers. They now usePrivateKey.generate(),CertificateRequestAttributes.generate_csr(),Certificate.generate_self_signed_ca()andCertificate.generate().haproxy-operator/tests/unit/legacy/test_haproxy_route_lib.py: themock_requirer_charmfixture never cleaned up its Harness. Its temporary directory was reclaimed by the garbage collector with aResourceWarning, which then failed whichever test happened to be running. The fixture now yields the harness and callscleanup().haproxy-route-policytest settings: WhiteNoise warnedNo directory at: .../static/because tests do not runcollectstatic. Both test settings now setWHITENOISE_AUTOREFRESH = True.Why we need it
Deprecation and resource warnings are easy to miss in CI logs. Promoting them to errors surfaces them when they are cheap to fix rather than when the API is removed. Turning it on here already found a real resource leak in the legacy test fixtures.
Test plan
-W errortoxrun passes in all five projects: lint, unit, static and coverage-report.DeprecationWarningfails, and one that leaks a file handle fails withResourceWarning. The probe file was not committed.Review focus
generate_ca()was given a throwaway key while the fixture returned a different one, so the issued certificate's signature did not match the CA's key. Tests pass either way, but the new pairing is the consistent one.haproxy-route-policy/tox.tomllistsunit-authinenvlistbut defines the env asunit_auth, so the auth tests do not run by default or in CI. They pass when run directly withtox -e unit_auth....:DeprecationWarning:charms.data_platform_libs, would keep the same deprecated call in this charm's own code failing. That form also passes the suite.no-release-notesince this changes only tests and test configuration.Checklist
docs/changelog.mdwith user-relevant changes (n/a: tests only)docs/release-notes/artifacts. If no change artifact is necessary, I tagged the PR with the labelno-release-note.This PR was assisted by an LLM.