-
-
Notifications
You must be signed in to change notification settings - Fork 12
basilisp test
always emits a PytestAssertRewriteWarning
message
#1252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I like option 1. |
I looked a bit more into the options here and I'm just not really sure any of the options presented are right or that this issue can be fixed by Basilisp in a good way. I found a related issue (pytest-dev/pytest#5473) in Pytest about this exact problem, which makes me think maybe Pytest needs a better functionality for suppressing this warning in such cases. If we go with option (1) (as you presented in PR #1255), then we will suppress that warning for presumably every plugin which might not be the desired behavior if users end up using other Pytest plugins. The warning text seems to disagree with their documentation which suggests only the module named in the plugin needs to be rewritten, since it is complaining about I think option (3) may work, but that would introduce additional complexity in requiring the testrunner to be a separate module. Since a significant portion of the Basilisp test suite depends on For now, I think if the warning is an issue it seems you can suppress it by invoking Pytest as either |
Actually, Pytest does mention basilisp and thus it provides the potential to filter the warning only for Basilisp:
Unfortunately, the
Since
unfortunately there does not appear to be a way to a escape a Trying to add an ignore filter with warning.filterwarnings import warnings
warnings.filterwarnings("ignore", message="Module already imported so cannot be rewritten: basilisp", category=pytest.PytestAssertRewriteWarning) doesn't work either because the function that emits the warning temporarily disables all filters: I plan to suggest to the Pytest team that they consider removing the As another manual workaround, regex-based filtering in the user's pyproject.toml can help in the meantime to suppress the error, although is not ideal (notice the pyproject.toml [tool.pytest.ini_options]
filterwarnings = [
"ignore:Module already imported so cannot be rewritten. basilisp:pytest.PytestAssertRewriteWarning",
]
It's more of an annoyance than a show-stopper, so I don't think there is a need to call pytest directly. We can live with it, but IMHO it should be addressed eventually. thanks |
|
Hi,
basilisp test
always emits aPytestAssertRewriteWarning
when run in a Basilisp project:PytestAssertRewriteWarning: Module already imported so cannot be rewritten: basilisp
To reproduce:
Poetry
and addbasilisp
andpytest
:basilisp test
, the above warning is emitted:The warning occurs because
basilisp
declares a pytest plugin in itspyproject.toml
:which results in the following entry point in the installed distribution:
As per assertion rewriting doc, any module registered as a
[pytest11]
plugin is subject to assertion rewriting. However, incli.py
,basilisp
is imported beforepytest.main()
is called, so pytest can't reimport the module for the purpose of rewriting its assertions, hence the warning.Options I can think of:
Silence the warning:
Since assertion rewriting is likely unnecessary for the Basilisp test runner plugin, this warning can probably be safely ignore. We can explicitly suppress this warning before calling
pytest.main()
.Unload the basilisp module before calling pytest:
Using
del sys.modules["basilisp"]
would technically allow pytest to reimport the module and rewrite it, but this is risky and could lead to inconsistencies, especially if anything from basilisp has already been used.Extract the test runner plugin into a separate package:
This avoids the warning entirely but comes at the cost of creating and maintaining a new separate basilisp-testrunner package.
I'm leaning toward option 1, and plan to raise a PR for it. If you have a better idea or prefer a different solution, please feel free to suggest.
Thanks
The text was updated successfully, but these errors were encountered: