是否有收集Setup/Teardown的方法?如果案例设置/拆卸错误,我可以恢复它?例如,我测试一个应用程序。
collection = list()
SESSION:
setup -> sucess # record it in to my collection collection.append(session.setup)
case 1:
setup -> sucess # record it in to my collection collection.append(case1.setup)
test -> sucess
teardown-> sucess # remove from my collection collection.remove(case1.setup)
case 2:
setup -> fail # traversing collections and run all setup again
我认为您的问题可以通过使用具有正确范围和产量的夹具来解决。当然,你可以根据自己的需要来修改函数/fixture。
@pytest.fixture(scope="session")
def my_session_setup():
my_setup_init()
@pytest.fixture()
def my_function_setup():
my_setup_init()
yield
my_setup_clean_up()
def test_first(my_session_setup, my_function_setup):
pass
def test_second(my_function_setup):
pass