在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
我想通过conftest.py做到这一点,以免影响现有的测试用例。
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")
但是它仍然运行拆解程序,并且出现如下所示的内部错误
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 ================================================================================