Skip to content

Session scoped fixtures can leak out of a class #2145

@jinty

Description

@jinty

Best explained with a failing test, see:

jinty@c0048b1

or inline for the lazy:

import pytest

@pytest.fixture(scope='session')
def foo():
    return 'foo'

@pytest.fixture(scope='session')
def bar(foo):
    return foo + 'bar'

@pytest.fixture(scope='session')
def baz(bar):
    return bar + 'baz'

class TestSpecific:

    @pytest.fixture(scope='session')
    def foo(self):
        return 'FOO'

    @pytest.fixture(scope='session')
    def baz(self, bar):
        return bar + 'BAZ'

    def test_b(self, foo, bar, baz):
        pass

def test_c(foo, bar, baz):
    assert foo == 'foo'
    assert bar == 'foobar'
    assert baz == 'foobarbaz'

Fails with the current master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions