跳到内容

pytest-erroneous-use-fixtures-on-fixture (PT025)

源自 flake8-pytest-style linter。

修复总是可用的。

作用

检查应用于 pytest fixture 的 pytest.mark.usefixtures 装饰器。

为什么这不好?

pytest.mark.usefixtures 装饰器对 pytest fixture 没有效果。

示例

import pytest


@pytest.fixture()
def a():
    pass


@pytest.mark.usefixtures("a")
@pytest.fixture()
def b(a):
    pass

建议改为

import pytest


@pytest.fixture()
def a():
    pass


@pytest.fixture()
def b(a):
    pass

参考