test.py
def test1():
raise Exception('Something happend')
assert True
@pytest.fixture
def fixt()
print('Some setup code')
yield
print('Some teardown code')
conftest.py
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
setattr(item, 'rep_' + rep.when, rep)
def pytest_runtest_teardown(item, nextitem):
request = item._request
if request.node.rep_call.failed:
print('Executing test failed', request.node.nodeid)
# Somehow skip the teardown in the "fixt" fixture...
由于 pytest_runtest_teardown
在任何其他夹具拆卸之前被调用,有没有办法从这里中止所有其他拆卸并退出?