1

I have defined 3 fixtures and set as autouse=True which gets executed for each test. I wanna print the summary for each fixture once all scoped fixture execution is done. Is there a way we can collect result and print summary. One solution I can think of using a global errors = list/dict to collect the errors and print summary using new fixture but just wondering if is there a better way handling it?


class Global:
    param1 = True
    param2 = False
    param3 = True

@pytest.fixture(autouse=True)
def fixture_1(request):
    # Do something.
    yield
    if Global.param1:
        print('Fixture_1 fail')
        raise Exception('Fixture_1 fail.')


@pytest.fixture(autouse=True)
def fixture_2(request):
    # Do something.
    yield
    if Global.param1:
        print('Fixture_2 fail')
        raise Exception('Fixture_2 fail.')


@pytest.fixture(autouse=True)
def fixture_3(request):
    # Do something.
    yield
    if Global.param1:
        print('Fixture_3 fail')
        raise Exception('Fixture_3 fail.')

Lad
  • 11
  • 1

0 Answers0