我有以下测试代码:
@pytest.fixture(autouse=True)
def _check(request, monkeypatch):
marker = request.node.get_marker('check')
if marker:
monkeypatch.setattr('collections.Counter', 'patched')
@pytest.mark.check()
def test_1():
import collections
assert collections.Counter == 'patched' # fine
@pytest.mark.check()
@pytest.fixture()
def set_mark():
pass
def test_2(set_mark):
import collections
assert collections.Counter == 'patched' # broken
test_1正常运行,但test_2出现故障。我希望将放置在固定装置中的标记器用于测试。
我该怎么做?
谢谢。