pytest-missing-fixture-name-underscore (PT004)
源自 flake8-pytest-style linter。
警告:此规则已被移除,其文档仅供历史参考。
移除
此规则已被移除,因为使用下划线标记不返回值的 fixture 不是 pytest 社区推荐的做法。
作用
检查不返回值,但名称没有以下划线开头的 pytest
fixture。
为什么这不好?
按照惯例,不返回值的 fixture 应以一个前导下划线命名,而返回值的 fixture 则不应。
此规则忽略抽象 fixture 和生成器。
示例
import pytest
@pytest.fixture()
def patch_something(mocker):
mocker.patch("module.object")
@pytest.fixture()
def use_context():
with create_context():
yield
建议改为
import pytest
@pytest.fixture()
def _patch_something(mocker):
mocker.patch("module.object")
@pytest.fixture()
def _use_context():
with create_context():
yield