-
Notifications
You must be signed in to change notification settings - Fork 214
Module already imported warning #148
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
Do you get other errors? AFAIK a mere warning can't change the exit code so the cause must be something else (some related exception somewhere?!) |
I think I overstated the problem. I'm running my tests using pytest-watch and its not continuing on to my |
Isn't that an issue in pytest-watch then? About the warning's source - are you importing pytest_cov in your code or how can I reproduce it? |
Sorry, I'm not really sure. 😄 I am not importing from pytest_cov or any other plugin, but pytest-cov is the only plugin reporting this warning. |
Are you using xdist? Hard to guess what the cause is. Can you make a reproducing example? |
Just to clarify, that warning is happening because by the time pytest is importing At a glance, I think the order is:
|
I've just started using xdist and running pytest -f and got the same error:
Also it created some new coverage files
I'm also getting wrong results when running with the
the content of pytest.ini:
|
I'm getting the same error, if I use pytest-xdist and the |
Here's the most minimal setup for reproducing this error:
Empty file
Run:
|
@nicoddemus
It looks like this warning is internal, and filters are not applied to it?! (see also #211) |
@blueyed unfortunately, internal warnings were introduced before pytest-warnings was integrated into the core, so they cannot be filtered using standard warning mechanisms. We have plans to update the internal warnings system to use the standard The internal warnings can be suppressed from the output with |
Found a workaround: #228 |
Minimal project to reproduce: https://github.com./ykvch/pytestwarning In my case warning appears when package:
So when the test discovery happens (e.g.: Note: NOT reproduced when using native style namespace (without find_packages) OR package is not installed. My solution: use native namespace package style. |
Sounds like a pytest issue then, i.e. it should be improved there I guess. |
At https://packaging.python.org/guides/packaging-namespace-packages they say: "While this approach is no longer recommended, it is widely present in most existing namespace packages." |
@ykvch |
@blueyed yes, general note for those, who still may experience this to show that there might be an alternative reason (and provide solution). You're right that comment above should be attached somewhere to pytest project as well. |
@ykvch
With regard to pytest I've found an interesting note in this context: https://github.com./pypa/setuptools/blob/d8b901bc15e2e365c7994cd65758f4181f3d9175/docs/pkg_resources.txt#L162-L171 - created pytest-dev/pytest#4980 for that. |
Cause we are loading config and defaults from our run_ocsci.py wrapper we need to add PYTEST_DONT_REWRITE msg to dosctring of modules where we don't want to see warning. Documentation: https://docs.pytest.org/en/latest/reference.html#pytest-dont-rewrite-module-docstring Reference where I found about this workarround is mentioned here: pytest-dev/pytest-cov#148 (comment)
Cause we are loading config and defaults from our run_ocsci.py wrapper we need to add PYTEST_DONT_REWRITE msg to dosctring of modules where we don't want to see warning. Documentation: https://docs.pytest.org/en/latest/reference.html#pytest-dont-rewrite-module-docstring Reference where I found about this workarround is mentioned here: pytest-dev/pytest-cov#148 (comment)
Cause we are loading config and defaults from our run_ocsci.py wrapper we need to add PYTEST_DONT_REWRITE msg to dosctring of modules where we don't want to see warning. Documentation: https://docs.pytest.org/en/latest/reference.html#pytest-dont-rewrite-module-docstring Reference where I found about this workarround is mentioned here: pytest-dev/pytest-cov#148 (comment)
Do we have a clear solution or workaround for this problem? I am facing this because I have a pytest plugin that is part of my module, which is causing import before pytest-cov is loaded. See https://github.com./ansible-community/ansible-lint/blob/main/conftest.py#L8 I cannot really move the plugin outside the module because the testing submodule is part of public API of my tool, as some need them for testing the stuff they build on top of. |
When I run my tests using
pytest==3.0.6
andpytest-cov==2.4.0
, I see the following warning:which unfortunately causes pytest to return a non-zero exit code and make the test suite as failing.
I don't see this warning with
pytest==2.9.2
.If it helps, I found a similar issue reported in another library: pytest-dev/pytest-testinfra#125
The text was updated successfully, but these errors were encountered: