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

fixture called by fixtures keep the first context #3673

Closed
ggens opened this issue Jul 9, 2018 · 5 comments
Closed

fixture called by fixtures keep the first context #3673

ggens opened this issue Jul 9, 2018 · 5 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@ggens
Copy link

ggens commented Jul 9, 2018

Hi,
In the same test after a first call, fixture save context and not executed a second time.

let's me show you issue by this exemple as below:

import pytest

@pytest.fixture(name="deep_fixture")
def fixture(request):
    fixture_parent = request._parent_request.fixturename
    if fixture_parent == "fixture_1":
        return "deep_fixture_1"
    if fixture_parent == "fixture_2":
        return "deep_fixture_2"

@pytest.fixture(name="fixture_1")
def fixture_parent_1(request, deep_fixture):
    assert deep_fixture == "deep_fixture_1"

@pytest.fixture(name="fixture_2")
def fixture_parent_2(request, deep_fixture):
    assert deep_fixture == "deep_fixture_2"

def test_fixure_in_fixture(fixture_1 ,fixture_2):
    pass

I'd the result:

    @pytest.fixture(name="fixture_2")
    def fixture_parent_2(request, deep_fixture):
>       assert deep_fixture == "deep_fixture_2"
E       AssertionError: assert 'deep_fixture_1' == 'deep_fixture_2'
E         - deep_fixture_1
E         ?              ^
E         + deep_fixture_2
E         ?    
@pytestbot pytestbot added topic: fixtures anything involving fixtures directly or indirectly type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature labels Jul 9, 2018
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #833 (--fixtures only shows fixtures from first file), #3661 (deprecate calling fixtures as functions), #2981 (Session fixture keeps frames of other fixtures alive), #1953 (Extending a fixture does not keep its params), and #2934 (capsysbinary fixture).

@ggens
Copy link
Author

ggens commented Jul 9, 2018

yes, it looks like #2981 but with function scope

@RonnyPfannschmidt
Copy link
Member

This is just completely invalid as a issue

@ggens
Copy link
Author

ggens commented Jul 9, 2018

@RonnyPfannschmidt i would like understand why ? Can me explain the reason please ?

@RonnyPfannschmidt
Copy link
Member

@ggens you used a private api that you shouldn't have accessed to begin with and you ignored that fixtures are cached per scope and are not made per usage site

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: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

3 participants