Skip to content

return-in-generator (B901) - should not be reported on pytest hook wrappers #21881

@DetachHead

Description

@DetachHead

Summary

from collections.abc import Generator

from pytest import TestReport, hookimpl


@hookimpl(wrapper=True)
def pytest_runtest_makereport() -> Generator[None, TestReport, TestReport]:
    result = yield
    result.outcome = "passed"
    return result # error: return-in-generator (B901)

this is the intended usage of pytest hook wrappers. see https://docs.pytest.org/en/stable/how-to/writing_hook_functions.html#hook-wrappers-executing-around-other-hooks

this behavior was introduced in 0.14.8 (#21200)

Version

0.14.8

Metadata

Metadata

Assignees

Labels

help wantedContributions especially welcomepreviewRelated to preview mode featuresruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions