0

I'm trying to write a fixture to achieve such function:

do something;
run the test case;
do something;
re-run the test case

I write my fixture like this:

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)

And decorate my test like this:

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

Then I got an error:

self = <_pytest.store.Store object at 0x7f9f38c97c78>, key = <_pytest.store.StoreKey object at 0x7f9f4a4d74b0>

def __delitem__(self, key: StoreKey[T]) -> None:
    """Delete the value for key.

    Raises ``KeyError`` if the key wasn't set before.
    """
    my_key = self._store.get(key)
    del self._store[key]
    KeyError: <_pytest.store.StoreKey object at 0x7f9f4a4d74b0>

It is said the environment has teared down after the frist time calling, after the second time calling, pytest will try to tear down the fixture environment againe, then error occur.

anyone can help?

I want to know how to rerun the test in its fixture, or some other method which can do automatic test re-run.

0 Answers0