Make assertion rewrite warning messages filterable #13429
Merged
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.
Hi,
can you please consider patch to mare assertion rewrite warning messages filterable using the standard
-W
option. It addresses #5473.The issue arises when a Python package defines a
pytest
plugin, and also callspytest.main()
programmatically, after importing one of its own submodules. Because the module is already imported,pytest.main()
cannot rewrite its assertions and emits a warning like:Module already imported so cannot be rewritten: basilisp
Unfortunately, the
:
in the message conflicts with Python’s warning filter syntax, where:
is used as a delimiter. This prevents users from filtering out the warning via-W
.This patch replaces the
:
in the warning message with a;
, making it possible to write a valid warning filter like:-W ignore:Module already imported so cannot be rewritten; mymodule:pytest.PytestAssertRewriteWarning
We believe there's no need to force assertion rewriting simply because a module defines a plugin, and users should be able to suppress this warning when needed.
For background and alternative solutions considered, see #5473 (comment).
Happy to discuss further or consider alternatives.
changelog
folderThanks