Repository navigation
Emit deprecations through WarningTemplate.warn; fix the instance #14931 missed - #15137
Draft
RonnyPfannschmidt wants to merge 1 commit into
Draft
RonnyPfannschmidt wants to merge 1 commit into
RonnyPfannschmidt wants to merge 1 commit into
Conversation
Follow-up to pytest-dev#14931, which made every constant in _pytest.deprecated an UnformattedWarning and had each call site do warnings.warn(X.format(), stacklevel=N). Rename UnformattedWarning to WarningTemplate, keeping the old name as an alias, and give it warn(): it builds the fresh instance, absorbs the +1 stacklevel for its own frame so callers keep the stacklevel they had, and hides that frame from tracebacks. format() only runs str.format() when kwargs are given, so constant messages may carry literal braces. A guard test walks every _pytest module for module-level Warning instances. It found INI_STRING_TYPE_NON_STR_VALUE, which pytest-dev#14931 missed and which still grew its traceback under -W error; it is a template now. Co-Authored-By: Claude Opus 5.5 via Claude Code <noreply@anthropic.com>
RonnyPfannschmidt
force-pushed
the
fix-14912-fresh-deprecation-warnings
branch
from
October 14, 2026 07:32
a70925f to
4cddffa
Compare
WarningTemplate.warn; fix the instance #14931 missed
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.
Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.
Follow-up to #14931, which fixed #14912 by making the constants in
_pytest.deprecatedUnformattedWarnings, with each call site doingwarnings.warn(X.format(), stacklevel=N).Change
INI_STRING_TYPE_NON_STR_VALUEwas still a sharedPytestRemovedIn10Warninginstance, so under-W errorits traceback still grew with every raise. It is a template now.UnformattedWarningbecomesWarningTemplate, keeping the old name as an alias.WarningTemplate.warn(*, stacklevel=1, **kwargs)builds the fresh instance and accounts for its own frame, so call sites keep their stacklevel. It also hides that frame from tracebacks. All call sites use it.format()runsstr.format()only when kwargs are given, so constant messages may contain literal braces.Tests
_pytestmodule and fails on any module-levelWarninginstance. It found the one above.warn()reports the caller's frame for eachstacklevel.Open question
UnformattedWarningalias?_pytest.warning_typesis private.