Skip to content

Relative ordering loses parameterized tests whose IDs contain brackets or node separators #272

Closed

Description

@jihtsan

On current main 4dcf4d448b90140af48ecd357dc3c3813e33e49a, a documented order(after="test_source") reference cannot resolve a parameterized test when its parameter ID contains an opening bracket. The marker is ignored and the dependent test executes first.

Reproduction (Python 3.12.14, pytest 9.2.0, macOS):

import pytest
seen = []

@pytest.mark.order(after="test_source")
def test_after():
    assert seen == ["done"]

@pytest.mark.parametrize("value", ["done"], ids=["outer[inner]"])
def test_source(value):
    seen.append(value)

pytest -q prints cannot execute 'test_after' relative to others: 'test_source' - ignoring the marker, then reports one failure and one pass. Expected: test_source runs before test_after, as documented for references without the parameter part.

Sorter derives the lookup key using the last [ and the last :: from a full node ID, then repeats the bracket parsing while matching. Those characters may occur in parameter IDs. Using pytest's collected function name and parent identity would keep parameter contents out of label matching.

Related #270 fixed class-scope grouping for :: IDs, but the remaining relative-label lookup is a separate path. Fully qualified references to individual parameter cases remain outside this report; the documented whole-test reference is the failing operation.

AI-assisted investigation; the failure above was executed locally.

Activity

  1. added a commit that references this issue on Oct 29, 2026
    7faa5e0
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions