Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session scoped fixtures can leak out of a class #2145

Open
jinty opened this issue Dec 19, 2016 · 4 comments
Open

Session scoped fixtures can leak out of a class #2145

jinty opened this issue Dec 19, 2016 · 4 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed

Comments

@jinty
Copy link

jinty commented Dec 19, 2016

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.

@decentral1se
Copy link
Contributor

Yep, reproduced this one with wget goo.gl/CDgb12 -O test_2145.py && pytest.

I thought scope=session fixtures were global, so this is expected?

@jinty
Copy link
Author

jinty commented Dec 20, 2016 via email

@RonnyPfannschmidt
Copy link
Member

the short story is, fixture declaration and mapping declarations to locations and caches is a complete mess and needs major refactoring ^^

@nicoddemus
Copy link
Member

While I agree with @RonnyPfannschmidt that the fixture system could use a refactoring to account for the features added in the last years, this warrants more investigation because I think there's a bug that should be solvable here; test_c should not have been able to see the fixtures declared by TestSpecific.

@nicoddemus nicoddemus added the type: bug problem that needs to be addressed label Feb 15, 2017
@nicoddemus nicoddemus added the topic: fixtures anything involving fixtures directly or indirectly label Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

4 participants