Skip to content

Session-scoped fixture executed too many times with -x / --maxfails #1024

Closed
@Garrett-R

Description

@Garrett-R

This is related, but I think slightly different than #868 and #420 (which deals with the fact that these flags do not stop execution after a fail).

Observe this test file:

import sys
from time import sleep

from pytest import fixture

# hack for live prints (https://stackoverflow.com/questions/27006884)
sys.stdout = sys.stderr


@fixture(scope='session', autouse=True)
def session_fixture():
    print('### executing fixture! ###')


def test_1():
    assert False


def test_2():
    sleep(1)


def test_3():
    sleep(1)


def test_4():
    sleep(1)

Running this with:

pytest test_parallel.py  -n 2  -s --maxfail=1

leads to the session_fixture being executed 3 times! Removing --maxfail=1, you can see session_fixture is executed twice (as expected).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions