Skip to content

Incorrect test ids generation when mixing dynamic parameterized and static fixtures #8372

Description

@ws1088

Issue: when i define dynamic parameterization and static parameterization of different fixtures, the generated ids of tests using both are messed up, depending on how you call pytest.

Tested on python 3.7.4, 3.8.2 with pytest 6.2.2

Setup:
image

conftest.py:

import _pytest.python
import pytest
def pytest_generate_tests(metafunc: _pytest.python.Metafunc):
    if 'fixture_a' in metafunc.fixturenames:
        metafunc.parametrize('fixture_a', ['a1', 'a2'])
    # if 'fixture_b' in metafunc.fixturenames:
        # metafunc.parametrize('fixture_b', ['b3', 'b4'])

@pytest.fixture(params=['b3', 'b4'])
def fixture_b(request):
    return request.param

test_general.py:

import _pytest.python
import pytest


def test_b(fixture_a, fixture_b):
    print('test_b', fixture_a, fixture_b)
    assert True

Running pytest --co dir1:
image

Running pytest --co dir1/dir2:
image

Notice the test ids are incorrect (fixture_b comes first)

If I use the change fixture_b to use dynamic parameterization then the test ids would be correct (uncomment the lines in conftest.py and comment out the static parameterization.

Activity

  1. added
    topic: fixturesanything involving fixtures directly or indirectly
    on Feb 26, 2021
  2. Zac-HD commented on Jul 22, 2026

    @Zac-HD
    Member

    Closing as resolved: reproducing the exact repro on current main shows stable, invocation-independent test ids now, which lines up with the pytest 8.0.0 rewrite of the fixture-closure/parametrize pipeline (#11416, #11220) — the two changes in that release most directly touching this code path. If anyone can still reproduce a similar mismatch on a current pytest version, please open a fresh issue with a minimal repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytopic: parametrizerelated to @pytest.mark.parametrize

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions