-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Remove dynamic setup of pytest.collect
fake module
#6803
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
Remove dynamic setup of pytest.collect
fake module
#6803
Conversation
Make it a real module instead. This was initially added in 9b58d6e (pytest-dev#2315), when removing support for `pytest_namespace`. Not sure if it ever worked "properly", but currently `import pytest.collect` and `from pytest.collect import File` do not work (but with this patch). This is only relevant for (backward) compatibility, but the more it appears to make sense to move it into a lazily loaded, separate file.
01e4e44
to
9815b69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing the attribute is a breaking change, we should deprecate it and keep importing it
this was introduced when pytest itself was NOT a package, its just icky and should be taken away
@RonnyPfannschmidt |
But you either have to do eager import or cut a major release |
src/pytest/__init__.py
Outdated
del _setup_collect_fakemodule | ||
def __getattr__(name): | ||
if name == "collect": | ||
from _pytest.compat import _setup_collect_fakemodule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps follow the previous approach of using a real module (say _pytest._collect
) and use it here?
def __getattr__(name):
if name == "collect":
from _pytest import _collect as collect
return collect
raise `AttributeError(name)`
Hmmm unfortunately __getattr__
is Python 3.7 only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep the original code as-is, given that it is supposed to not stay anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a follow-up or inline, adding to sys. Modules and adding a deprecation warning subclass of the module type should improve the general situation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding to sys.modules would likely break that test: https://github.com/pytest-dev/pytest/pull/6803/files#diff-dc953e3e35889673e6c7ba78247b25d9R49-R50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecation warning should be done in a follow-up.
You mean using a real import on I would be OK with that, currently we are already paying the price of importing those names anyway. One problem is that I can't think of a way of deprecating that, unfortunately. (The |
The eager import was done in 8a8b1f6. We can use |
Taken out of pytest-dev#6733, returning for existing symlink (should not skip).
Missing coverage is due to |
Good idea, this way we can upgrade to the py37+ only version when the time comes to drop py36.
I gave this another go, but no luck yet (left a comment on that PR). |
Btw I don't think that should block this. |
Me neither - but would be good that it works / is covered for non-admin users. |
Oh that's what you meant to convey on #6803 (comment)? I thought you meant that this should be blocked until that gets resolved. Clear now. 👍 |
Make it a real module instead.
This was initially added in 9b58d6e
(#2315), when removing support
for
pytest_namespace
.Not sure if it ever worked "properly", but currently
import pytest.collect
andfrom pytest.collect import File
do notwork (but with this patch).
This is only relevant for (backward) compatibility, but the more it
appears to make sense to move it into a lazily loaded, separate file.