How to ignore tests when session fixture fails in pytest

Viewed 1946

Let's say I have a test as shown below:

import pytest
import copy

@pytest.fixture(scope='session')
def session_tool(request):
    tool = request.config.tool
    # Build is the critical part and may fail, raising an exception
    tool.build()
    return tool

@pytest.fixture
def tool(session_tool):
    return copy.deepcopy(session_tool)

def test_tool(tool, args):
    assert tool.run(args) == 0

It builds a session-scoped tool and then creates a copy of it for each testcase. But when the build fails, session_tool fixture is executed again for the next testcase, which fails again... until it fails for all testcases. As there are a lot of testcases, it takes some time until the process is finished.

Is there any way to tell pytest to skip all tests which use session_fixture after the first attempt to build fails?

1 Answers
Related