Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 768 Bytes

PT004.md

File metadata and controls

43 lines (30 loc) · 768 Bytes

PT004

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

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.