How to skip teardown when assertion occured in pytest
import logging
import pytest
log = logging.getLogger(__name__)
@pytest.fixture()
def myfixture(request):
self = request.node.cls
setup(self)
yield
teardown()
def setup(self):
log.info("In setup")
def teardown():
log.info("In teardown but I don't want to execute this after assertion")
class TestCase():
def test_case1(self, myfixture):
log.info("Running test_case1")
assert 3 == 7
I would like to achieve this through conftest.py so that it won't effect the existing test cases.
conftest.py
import pytest
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
if rep.when == "call" and rep.failed:
pytest.skip("skipping")
But it still runs the teardown and also its getting Internal Error like below
INTERNALERROR> raise Skipped(msg=msg, allow_module_level=allow_module_level)
INTERNALERROR> Skipped: skipping
----------------------------------------------------------------------------------- live log sessionfinish -----------------------------------------------------------------------------------
INFO - In teardown but I don't want to execute this after assertion
================================================================================ no tests ran in 0.19 seconds ================================================================================