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

deprecate marker based hook metadata #4562

Closed
RonnyPfannschmidt opened this issue Dec 19, 2018 · 3 comments · Fixed by #9118
Closed

deprecate marker based hook metadata #4562

RonnyPfannschmidt opened this issue Dec 19, 2018 · 3 comments · Fixed by #9118
Labels
topic: marks related to marks, either the general marks or builtin type: deprecation feature that will be removed in the future

Comments

@RonnyPfannschmidt
Copy link
Member

followup to #891

while implementing i noticed we support attribute/mark based hook metadata just in pytest,
we should deprecate that custom parsing and rely entirely on pluggy markers

@RonnyPfannschmidt RonnyPfannschmidt added the type: deprecation feature that will be removed in the future label Dec 19, 2018
@blueyed
Copy link
Contributor

blueyed commented Apr 13, 2019

Just for reference: instead of @pytest.mark.hookwrapper @pytest.hookimpl(hookwrapper=True) should be used.
Related code:

def parse_hookimpl_opts(self, plugin, name):
# pytest hooks are always prefixed with pytest_
# so we avoid accessing possibly non-readable attributes
# (see issue #1073)
if not name.startswith("pytest_"):
return
# ignore names which can not be hooks
if name == "pytest_plugins":
return
method = getattr(plugin, name)
opts = super(PytestPluginManager, self).parse_hookimpl_opts(plugin, name)
# consider only actual functions for hooks (#3775)
if not inspect.isroutine(method):
return
# collect unmarked hooks as long as they have the `pytest_' prefix
if opts is None and name.startswith("pytest_"):
opts = {}
if opts is not None:
# TODO: DeprecationWarning, people should use hookimpl
# https://github.com/pytest-dev/pytest/issues/4562
known_marks = {m.name for m in getattr(method, "pytestmark", [])}
for name in ("tryfirst", "trylast", "optionalhook", "hookwrapper"):
opts.setdefault(name, hasattr(method, name) or name in known_marks)
return opts

(I've just came along about a plugin using @pytest.mark.hookwrapper and looked it up)

blueyed added a commit to blueyed/testmon that referenced this issue Apr 13, 2019
Matlino pushed a commit to tarpas/pytest-testmon that referenced this issue May 14, 2019
@Zac-HD Zac-HD added the topic: marks related to marks, either the general marks or builtin label Jun 24, 2019
@bluetech bluetech added this to the 6.1 milestone Jun 21, 2020
@bluetech
Copy link
Member

I added this to the 6.1 milestone: hopefully we can start emitting deprecation warnings in 6.x. However the @pytest.mark.{tryfirst,trylast,hookwrapper,optionalhook} hooks are very commonly used in external plugins so not sure when it would make sense to completely remove.

@nicoddemus nicoddemus modified the milestones: 6.1, 6.2 Aug 19, 2020
@RonnyPfannschmidt
Copy link
Member Author

@nicoddemus while investigating i noted, that it seems like we dont have a good way to issue/record warnings with specific locations at that point in time,

this seems hard to correctly fix at first glance, so i will defer it until i can spend some more time with the issue at hand

@RonnyPfannschmidt RonnyPfannschmidt removed this from the 6.2 milestone Nov 21, 2020
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Sep 23, 2021
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Oct 1, 2021
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Oct 2, 2021
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Oct 3, 2021
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Oct 10, 2021
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Nov 17, 2021
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Feb 27, 2022
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Mar 6, 2022
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Mar 8, 2022
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue May 15, 2022
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Jul 29, 2022
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Jul 30, 2022
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Jul 31, 2022
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Sep 20, 2022
RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this issue Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: marks related to marks, either the general marks or builtin type: deprecation feature that will be removed in the future
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants