Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 770 Bytes

PT005.md

File metadata and controls

45 lines (32 loc) · 770 Bytes

PT005

fixture '{name}' returns a value, remove leading underscore

Examples

Bad code:

import pytest

@pytest.fixture()
def _some_object():
    return SomeClass()

@pytest.fixture()
def _some_object_with_cleanup():
    obj = SomeClass()
    yield obj
    obj.cleanup()

Good code:

import pytest

@pytest.fixture()
def some_object():
    return SomeClass()

@pytest.fixture()
def some_object_with_cleanup():
    obj = SomeClass()
    yield obj
    obj.cleanup()

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 PT004.