Skip to content

Troubles to understand the new updates on Pluggy #468

Open
@Tiarles

Description

@Tiarles

Hi everybody.

I am having issues updating my pytest plugin after pluggy==1.0.0 updates. Accordingly, with the documentation all the hooks decorated with hookwrapper=True need to be written as a generator because, without this, it would cause an error later. In my application, the hook wrappers were always a generator but the PluginValidationError is still being thrown. I isolated the if statement (Code snippet 1) for that Error and my hook wrapper passes, but not in the pluggy (on .\py38\lib\site-packages\pluggy\_manager.py file) implementation which always falls on the exception:

# Code snippet 1: Lines 341 to 358 from pluggy\_manager.py (version pluggy==1.3.0)
if (
    hookimpl.wrapper or hookimpl.hookwrapper
) and not inspect.isgeneratorfunction(hookimpl.function):
    raise PluginValidationError(
        hookimpl.plugin,
        "Plugin %r for hook %r\nhookimpl definition: %s\n"
        "Declared as wrapper=True or hookwrapper=True "
        "but function is not a generator function"
        % (hookimpl.plugin_name, hook.name, _formatdef(hookimpl.function)),
    )

Also, the changelog for the version 1.0.0 is very confusing. First, the exception name is PluginValidationError and not PluggyValidationError as is written there. Second is that the example to properly make the changes has functions that are not used and others that have no reference in the documentation for it (Code snippet 2).

# Code snippet 2.1: Changed example from Pluggy CHANGELOG version 1.0.0

def my_hook_real_implementation(arg):  # Function created but not used on the documenation
    print("before")
    yield
    print("after")


@hookimpl(hookwrapper=True)
def my_hook(arg):
    return my_hook_implementation(arg)  # Not declared function

change it to use yield from instead:

# Code snippet 2.2: Changed example from Pluggy CHANGELOG version 1.0.0
@hookimpl(hookwrapper=True)
def my_hook(arg):
    yield from my_hook_implementation(arg)  # Not declared function

I considered in this example that my_hook_real_implementation is the function my_hook_implementation but still my hook wrap falls in the same exception.

I comment the Code Snippet 1 in my enviroment with the same version of Pluggy and the execution happened with no errors.

I don`t know what is needed to fix this issue on my side, maybe a more explanatory example could be provided or maybe pluggy needs updates.

Let me know which more data is needed or what I can do it to help. Since my plugin code is from the repository of the company that I work, I didn`t provided the source code here but we can arrange some way to get more data and a reproduceable example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions