Skip to content

Latest commit

 

History

History
49 lines (34 loc) · 1.05 KB

PT004.md

File metadata and controls

49 lines (34 loc) · 1.05 KB

PT004

fixture '{name}' does not return anything, add leading underscore

This rule does not fire on abstract fixtures (those decorated with @abc.abstractmethod), so that only the actual fixture implementations will be checked.

This rule also does not fire on fixtures containing yield from, because there is no reasonable way to determine whether the generator yields a value.

Examples

Bad code:

import pytest

@pytest.fixture()
def patch_something(mocker):
    mocker.patch('module.object')

@pytest.fixture()
def use_context():
    with create_context():
        yield

Good code:

import pytest

@pytest.fixture()
def _patch_something(mocker):
    mocker.patch('module.object')

@pytest.fixture()
def _use_context():
    with create_context():
        yield

Rationale

  • to enforce a naming convention for fixtures: fixtures that don't return a value start with a leading underscore (e.g. _patch_something), fixtures that return a value don't start with a leading underscore (e.g. some_object)

See also PT005.