相关疑难解决方法(0)

标记 Pytest 夹具而不是使用该夹具的所有测试

有没有办法在 PyTest 夹具中定义标记?

当我在 pytest.txt 中指定时,我试图禁用慢速测试-m "not slow"

我已经能够禁用单个测试,但不能禁用用于多个测试的固定装置。

我的夹具代码如下所示:

@pytest.fixture()
@pytest.mark.slow
def postgres():
    # get a postgres connection (or something else that uses a slow resource)
    yield conn 
Run Code Online (Sandbox Code Playgroud)

一些测试具有以下一般形式:

def test_run_my_query(postgres):
    # Use my postgres connection to insert test data, then run a test
    assert ...
Run Code Online (Sandbox Code Playgroud)

我在https://docs.pytest.org/en/latest/mark.html更新的链接)中找到了以下评论:

“标记只能用于测试,对灯具没有影响。” 这个评论的原因是固定装置本质上是函数调用并且标记只能在编译时指定?

有没有一种方法可以指定使用特定固定装置(在本例中为 postgres)的所有测试都可以标记为慢,而无需@pytest.mark.slow在每个测试上指定?

pytest

15
推荐指数
1
解决办法
4537
查看次数

标签 统计

pytest ×1