Skip to content

How to return from hookwrapper in python < 3.3 #3169

@fruch

Description

@fruch

I have a warning that _multicall is deprecated, so I have to change the code I have

@pytest.hookimpl(tryfirst=True)
def pytest_runtest_makereport(___multicall__):
    # Execute all other hooks to obtain the report object.
    rep = ___multicall__.execute()
    if rep.failed:
            # my logic to figure out I want to xfail
            if 'decided I want to xfail':
                TestApi.add_analysis('socket hang up')
                setattr(rep, "outcome", "skipped")
                setattr(rep, "wasxfail", 'socket hang up')
                return rep
    return rep

to this code:

@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport():
    # Execute all other hooks to obtain the report object.
    outcome = yield
    rep = outcome.get_result()
    if rep.failed:
            # my logic to figure out I want to xfail
            if 'decided I want to xfail':
                TestApi.add_analysis('socket hang up')
                setattr(rep, "outcome", "skipped")
                setattr(rep, "wasxfail", 'socket hang up')
                return rep
    return rep

problem python < 3.3 doesn't support returning from a generator, so how am I supposued to return a modified result ?
changing the object in-place would be enough ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions