Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 673 Bytes

PT022.md

File metadata and controls

39 lines (28 loc) · 673 Bytes

PT022

no teardown in fixture {name}, use return instead of yield

yield in fixtures is only useful and semantically correct when the fixture contains some teardown code.

Examples

Bad code:

import pytest

@pytest.fixture()
def my_fixture():
    resource = acquire_resource()
    yield resource

Good code:

import pytest

@pytest.fixture()
def my_fixture_with_teardown():
    resource = acquire_resource()
    yield resource
    resource.release()

@pytest.fixture()
def my_fixture_without_teardown():
    resource = acquire_resource()
    return resource

Rationale

  • to make sure that all yield usages are semanticaly correct