как пропустить разбор при утверждении в pytest - PullRequest
1 голос
/ 17 июня 2019

Как пропустить разрыв, когда утверждение произошло в 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 ================================================================================

...