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

Parametrized fixture being used by other fixtures #7737

Open
nicoddemus opened this issue Sep 10, 2020 · 0 comments
Open

Parametrized fixture being used by other fixtures #7737

nicoddemus opened this issue Sep 10, 2020 · 0 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly

Comments

@nicoddemus
Copy link
Member

This issue is split from #1953.

The following test shows a case which is not currently supported: foo is parametrized, and used indirectly through bar, which is also overwritten closer to the test:

    def test_extend_fixture_with_parametrized_dependency(self, testdir):
        testdir.makeconftest("""
            import pytest

            @pytest.fixture(params=[1])
            def foo(request):
                return request.param

            @pytest.fixture
            def bar(foo):
                return foo
        """)
        testfile = testdir.makepyfile("""
            import pytest

            @pytest.fixture
            def bar(bar):
                return bar * 2

            def test_spam(bar):
                assert bar == 2
        """)
        result = testdir.runpytest(testfile)
        result.stdout.fnmatch_lines(["*1 passed*"])

The current fixture parametrization mechanism implemented in FixtureManager doesn't follow the fixture dependencies to apply fixture parametrization, it only looks at the argument names of the function explicitly (those in Metafunc).

More investigation is needed.

Workaround

A workaround is to re-specify the dependency to foo in bar.

    def test_extend_fixture_with_parametrized_dependency(self, testdir):
        testdir.makeconftest("""
            import pytest

            @pytest.fixture(params=[1])
            def foo(request):
                return request.param

            @pytest.fixture
            def bar(foo):
                return foo
        """)
        testfile = testdir.makepyfile("""
            import pytest

            @pytest.fixture
            def bar(bar, foo):
                return bar * 2

            def test_spam(bar):
                assert bar == 2
        """)
        result = testdir.runpytest(testfile)
        result.stdout.fnmatch_lines(["*1 passed*"])

Thanks to @jmoldow for the original report.

@nicoddemus nicoddemus added the topic: fixtures anything involving fixtures directly or indirectly label Sep 10, 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
Projects
None yet
Development

No branches or pull requests

1 participant