Make assertion rewrite warning messages filterable #13429
Conversation
so it can be filtered using standard Python warning filters.
nicoddemus
left a comment
There was a problem hiding this comment.
Looks great, simple and to the point! Thanks @ikappaki!
|
Arent other regex matches avaliable to match? |
|
The issue is that the string passed to the -W command line option is treated as a literal, so regex characters have no effect: i.e., in CPython, the |
|
So we should aim for warning filters in pytest settings instead of using slightly off characters in the long run |
You OK to merge the PR or would you like to hold it off to discuss it further? |
|
Let's merge it for now But eventually id like to be able to block the warnings properly |
…-dev#13429) This makes it possible to filter them using standard Python warning filters. --- Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
Hi, can you please consider patch to suppress the pytest rewrite assertion warning when running `basilisp test`. It fixes #1252. I haven’t added a test, as it would require creating a virtual environment during testing, which seemed excessive for this issue. However, I’m happy to add one if you feel it’s necessary. Thanks Note: this is a follow up to #1255 but it uses the `;` separator to specify the module name, introduced by pytest-dev/pytest#13429 in [Pytest 8.4.0](https://docs.pytest.org/en/stable/changelog.html#pytest-8-4-0-2025-06-02). --------- Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>

Hi,
can you please consider patch to mare assertion rewrite warning messages filterable using the standard
-Woption. It addresses #5473.The issue arises when a Python package defines a
pytestplugin, 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: basilispUnfortunately, 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.PytestAssertRewriteWarningWe 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.
changelogfolderThanks