pytest 测试是否可以更改会话固定装置的值并影响后续测试?

问题描述 投票:0回答:1

假设 pytest 会话装置返回一个字典,然后在测试中操作该字典。这会影响后续测试吗?

python pytest fixtures
1个回答
0
投票

是的。这很容易验证。这些测试中的一项将会失败:

import pytest

@pytest.fixture(scope="session")
def d():
    return {}

def test_one(d):
    assert not d
    d["k"] = "v"

def test_two(d):
    assert not d
    d["k"] = "v"
© www.soinside.com 2019 - 2024. All rights reserved.