在 pytest 夹具中重新运行装饰测试

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

我正在尝试编写一个夹具来实现这样的功能:

do something;
run the test case;
do something;
rerun the test case

我这样写我的夹具:

def dosomething1(path):
    pass

def dosomething2(path):
    pass

@pytest.fixture()
def uniform_tests(request):
    path= request.param
    dosomething1(path)
    yield
    dosomething2()
    request.node.config.hook.pytest_runtest_protocol(item=request.node, nextitem=None)

像这样装饰我的测试:

@pytest.mark.parametrize('uniform_tests', ['path to my file',], indirect=True)
def test_MC_MagnetAutocall(other_fixtures, uniform_tests):
    pass

然后我得到一个错误:

RuntimeError: Error in function alib_MCAutocallResetableEngine : Cannot store object with ID 'TestMagnetAutocall.Engine' because an object with that ID already exists

当我将测试 id 传递给 pytest 时,看起来有 id 冲突(原始测试仍然存在)。
有人可以帮忙吗?

我想知道如何在其夹具中重新运行测试。

python pytest fixtures pytest-fixtures
© www.soinside.com 2019 - 2024. All rights reserved.