Skipping teardown from the pytest_runtest_teardown hook

Viewed 136

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...

Since pytest_runtest_teardown is being called before any other fixture teardown, is there a way to abort all other teardown from here and exit?

0 Answers
Related