Skip to content

Recursive parameterized fixture bug #6416

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

Open
baszalmstra opened this issue Jan 7, 2020 · 0 comments
Open

Recursive parameterized fixture bug #6416

baszalmstra opened this issue Jan 7, 2020 · 0 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed

Comments

@baszalmstra
Copy link

Description

When overriding session scoped fixtures with a parameterized fixture that is used as the input to another fixture the recursive fixture is not properly invoked.

I have created a minimal reproduction here with more information: https://github.com/baszalmstra/pytest_fixture_bug

Minimal example

Given the files:

conftest.py

import pytest


@pytest.fixture(scope="session")
def parameterized_fixture(request):
    return request.param


@pytest.fixture(scope="session")
def recursive_fixture(parameterized_fixture):
    print("Calling recursive_fixture with: {}".format(parameterized_fixture))
    return parameterized_fixture

test_bar.py

import pytest


@pytest.fixture(scope="session", params=["bar1"])
def parameterized_fixture(request):
    print("Calling parameterized_fixture with: {}".format(request.param))
    return request.param


def test_bar(recursive_fixture):
    print("Calling test_foo with: {}".format(recursive_fixture))
    assert("bar" in recursive_fixture)

test_foo.py

import pytest


@pytest.fixture(scope="session", params=["foo1", "foo2"])
def parameterized_fixture(request):
    print("Calling parameterized_fixture with: {}".format(request.param))
    return request.param


def test_foo(recursive_fixture):
    print("Calling test_bar with: {}".format(recursive_fixture))
    assert("foo" in recursive_fixture)

Calling pytest fails with:

________________________________ test_foo[foo1] ________________________________

recursive_fixture = 'bar1'

    def test_foo(recursive_fixture):
        print("Calling test_bar with: {}".format(recursive_fixture))
>       assert("foo" in recursive_fixture)
E       AssertionError: assert 'foo' in 'bar1'

test_foo.py:12: AssertionError
---------------------------- Captured stdout setup -----------------------------
Calling parameterized_fixture with: foo1
----------------------------- Captured stdout call -----------------------------
Calling test_bar with: bar1

Which should not be possible.

We have observed this issue with both pytest-4.6.9 as well as with pytest-5.3.2 on Ubuntu 18.04. We are still on python 2.7 so a backported solution to pytest 4 would be desirable.

This seems to be related to: #5693

@Zac-HD Zac-HD added topic: fixtures anything involving fixtures directly or indirectly type: bug problem that needs to be addressed labels Jan 8, 2020
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

2 participants