Skip to content

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

Closed

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Feb 24, 2020

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 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.

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.
@blueyed blueyed force-pushed the rm-_setup_collect_fakemodule-upstream branch from 01e4e44 to 9815b69 Compare February 24, 2020 03:22
@blueyed blueyed mentioned this pull request Feb 24, 2020
1 task
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a 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

@blueyed
Copy link
Contributor Author

blueyed commented Feb 26, 2020

@RonnyPfannschmidt
What do you mean by "removing the attribute"?
This adds a test for compat that might have even failed before (if being more strict), since now the "attribute" actually behaves like a module.

@RonnyPfannschmidt
Copy link
Member

But you either have to do eager import or cut a major release

del _setup_collect_fakemodule
def __getattr__(name):
if name == "collect":
from _pytest.compat import _setup_collect_fakemodule
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

@nicoddemus
Copy link
Member

nicoddemus commented Feb 26, 2020

But you either have to do eager import

You mean using a real import on pytest.__init__, like it was done in 30a7a68?

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 __getattr__ module level that @blueyed proposes would be ideal for that, but it is Python 3.7+ only).

@blueyed
Copy link
Contributor Author

blueyed commented Feb 26, 2020

The eager import was done in 8a8b1f6.

We can use __getattr__ for py37+ then, and the old / unconditional code otherwise?

@blueyed
Copy link
Contributor Author

blueyed commented Feb 27, 2020

Missing coverage is due to symlink_or_skip - pending investigation by a Windows user (it seems like all of the CI jobs can create symlinks? - #6733).

@nicoddemus
Copy link
Member

nicoddemus commented Feb 27, 2020

We can use getattr for py37+ then, and the old / unconditional code otherwise?

Good idea, this way we can upgrade to the py37+ only version when the time comes to drop py36.

Missing coverage is due to symlink_or_skip - pending investigation by a Windows user

I gave this another go, but no luck yet (left a comment on that PR).

@nicoddemus
Copy link
Member

Missing coverage is due to symlink_or_skip - pending investigation by a Windows user

Btw I don't think that should block this.

@blueyed
Copy link
Contributor Author

blueyed commented Mar 3, 2020

Missing coverage is due to symlink_or_skip - pending investigation by a Windows user

Btw I don't think that should block this.

Me neither - but would be good that it works / is covered for non-admin users.

@nicoddemus
Copy link
Member

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. 👍

blueyed added a commit to blueyed/pytest that referenced this pull request Mar 12, 2020
@blueyed blueyed closed this Mar 27, 2020
@blueyed blueyed deleted the rm-_setup_collect_fakemodule-upstream branch March 27, 2020 01:37
@blueyed blueyed mentioned this pull request Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants