Remove dynamic setup of pytest.collect fake module#6803
Remove dynamic setup of pytest.collect fake module#6803blueyed wants to merge 10 commits intopytest-dev:masterfrom
pytest.collect fake module#6803Conversation
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
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.collectandfrom pytest.collect import Filedo 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.