Skip to content

pytest-missing-fixture-name-underscore (PT004)#

Derived from the flake8-pytest-style linter.

What it does#

Checks for pytest fixtures that do not return a value, but are not named with a leading underscore.

Why is this bad?#

By convention, fixtures that don't return a value should be named with a leading underscore, while fixtures that do return a value should not.

This rule ignores abstract fixtures and generators.

Example#

import pytest


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


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

Use instead:

import pytest


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


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

References#