Skip to content

Snapshots of parameterized tests save in alphabetical order instead of declared order #968

Open
@james-seymour-cubiko

Description

@james-seymour-cubiko

When using @pytest.mark.parametrize with the ids argument, snapshots are saved in alphabetical order of ids instead of in the declared order. This makes snapshots harder to read, especially when there are many parametrisations and they are in some logical order (e.g. from simple to complex)

To reproduce

With a simple parameterised test setup such as

@pytest.mark.parametrize(
    argnames=("input"),
    argvalues=[
        ("test_b"),
        ("test_a"),
    ],
    ids=["b", "a"],
)
def test_input(input: str, snapshot: SnapshotAssertion):
    assert input == snapshot

syrupy will save the snapshots for these tests as

# name: test_input[a]
  'test_a'
# ---
# name: test_input[b]
  'test_b'
# ---

Expected behavior

I would expect that syrupy should save the snapshots for these tests as

# name: test_input[b]
  'test_b'
# ---
# name: test_input[a]
  'test_a'
# ---

Should this be the intended behaviour? If so, I'm happy to do the PR :)

Environment (please complete the following information):

  • OS: Fedora 40
  • Syrupy Version: 4.8.2
  • Python Version: 3.12.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions