Skip to content
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

Show full qualified name on direct Node construction warning #8994

Closed
nicoddemus opened this issue Aug 9, 2021 · 8 comments · Fixed by #9066
Closed

Show full qualified name on direct Node construction warning #8994

nicoddemus opened this issue Aug 9, 2021 · 8 comments · Fixed by #9066
Labels
good first issue easy issue that is friendly to new contributor plugin: warnings related to the warnings builtin plugin topic: reporting related to terminal output and user-facing messages and errors

Comments

@nicoddemus
Copy link
Member

In ESSS/pytest-regressions#64, running pytest with many plugins installed gives this error:

Direct construction of SpecModule has been deprecated, please use SpecModule.from_parent.
See https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent for more details.

And is not clear which plugin is the culprit, I had to look at the source code of pytest-relaxed to figure it out.

We might consider at least show the full qualified name of the offending class in that message, so users would see pytest_relaxed.plugin.SpecModule, which is a nudge in the right direction.

Originally posted by @nicoddemus in #8993 (comment)

@nicoddemus nicoddemus added plugin: warnings related to the warnings builtin plugin good first issue easy issue that is friendly to new contributor topic: reporting related to terminal output and user-facing messages and errors labels Aug 9, 2021
@eamanu
Copy link
Contributor

eamanu commented Aug 11, 2021

Hi! I would like to work in this issue :)

@nicoddemus
Copy link
Member Author

@eamanu thanks for volunteering! Please go ahead and let us know if you encounter any problems. 👍

@wassafshahzad
Copy link

Hi can I work on this as well ?

@eamanu
Copy link
Contributor

eamanu commented Aug 24, 2021

Hi, @wassafshahzad sure!! I looked into the pytest code to identify where that message is write. That is here [0], I spend several time trying to found where the name is "loaded" into a class that use the NodeMeta. But I cannot found nothing yet. So, I'm trying to access to the Node class [1] variables from NodeMeta, and I guess that we'll need to use inspect to get the "path" to the bad initialize class.

[0]

"Direct construction of {name} has been deprecated, please use {name}.from_parent.\n"

[1]
class Node(metaclass=NodeMeta):

@nicoddemus
Copy link
Member Author

Hi @eamanu @wassafshahzad,

Classes have a __module__ attribute which contain exactly the string we need:

>>> from _pytest.nodes import File
>>> File.__module__
'_pytest.nodes'

So unless I'm missing something it is just a matter of changing:

).format(name=self.__name__)

To:

).format(name=f"{self.__module__}.{self.__name__}")

@wassafshahzad
Copy link

Hi @eamanu @wassafshahzad,

Classes have a __module__ attribute which contain exactly the string we need:

>>> from _pytest.nodes import File
>>> File.__module__
'_pytest.nodes'

So unless I'm missing something it is just a matter of changing:

).format(name=self.__name__)

To:

).format(name=f"{self.__module__}.{self.__name__}")

so should we create a PR with this change ?

@nicoddemus
Copy link
Member Author

Yes pretty much. 😁

Make sure to add/update an existing test for the new behavior too.

@eamanu
Copy link
Contributor

eamanu commented Sep 1, 2021

I'm just create the PR, thanks @nicoddemus for the advice, was simpler that I imagine :)

The-Compiler added a commit to The-Compiler/pytest that referenced this issue Nov 8, 2021
This is an impovement for a warning introduced in this release, so including it in a changelog against the last release seems confusing.
The-Compiler added a commit that referenced this issue Nov 10, 2021
* Remove changelog entry for #8251

Reverted in #8903

* Move #9202 changelog to to trivial

This won't concern users of pytest

* Streamline deprecation changelogs/docs

* Remove #8994 changelog

This is an impovement for a warning introduced in this release, so including it in a changelog against the last release seems confusing.

* Remove #9241 changelog

This is an impovement for a doc update introduced in this release, so including it in a changelog against the last release seems confusing. The issue number also seems about something different.

* Remove #8897 changelog

Empty file...

* Various minor changelog fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor plugin: warnings related to the warnings builtin plugin topic: reporting related to terminal output and user-facing messages and errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants