Skip to content

yield_namespace_device_dtype_combinations parametrization ID confusing for 'device1' #31042

Closed

Description

@lucyleeow

Noticed in #29431 (comment)

In yield_namespace_device_dtype_combinations, for array_api_strict we yield CPU_DEVICE first, then device1. This results in the confusing pytest parametrization IDs:

  • array_api_strict-device2-float32 - where 'device2' actually refers to Device("device1") and not Device("device2")
  • array_api_strict-device1-float64 - where 'device1' actually refers to Device("CPU_DEVICE") and not Device("device1")

Not sure if there is an good fix for this / or if a fix is needed.

We could yield Device("device1") first but then the id "device2" would refer to Device("CPU_DEVICE") and not Device("device2")

The only way to completely avoid confusion would be to write a function that takes a params and amends the names e.g.,

@pytest.mark.parametrize(
    "namespace,device,dtype",
    list(yield_namespace_device_dtype_combinations()),
    ids=_get_namespace_device_dtype_test_ids
)

The BUT I am not sure if this is an over complicated solution to a trivial problem...

(Edit: We could just make a note in the yield_namespace_device_dtype_combinations docstring - this seems like a reasonable solution...)

Activity

  1. added
    Needs Triage
    on Mar 21, 2025
  2. lucyleeow commented on Mar 21, 2025

    @lucyleeow
    MemberAuthor

    Actually I've just realised that the ID 'device' depends on the number of namespaces supported in the environment, but the above does seem to be the case for a few of the azure workflows.

  3. betatim commented on Mar 21, 2025

    @betatim
    Member

    This also tripped me up a while back. So it is probably worth fixing.

    We use the "generate IDs" approach for other tests and it is really nice, so maybe we should just do that here as well. The other approach that could be nice, but not sure if it is feasible, is to modify array-api-strict's Device class so that it "automatically" gets represented nicer in tests. That would solve the problem for all people who use array-api-strict which would be nice.

  4. lucyleeow commented on Mar 21, 2025

    @lucyleeow
    MemberAuthor

    is to modify array-api-strict's Device class so that it "automatically" gets represented nicer in tests.

    I don't think this is possible. If it's not Numbers, strings, booleans and None, then pytest will use the argument name:

    https://docs.pytest.org/en/stable/example/parametrize.html#different-options-for-test-ids

    I was naively hoping a __str__ or __repr__ would do it but no. It actually may be a nice pytest feature to add.

    Happy to add a 'generate ID' function, if others don't think its adding too much complexity

  5. removed
    Needs Triage
    on Mar 21, 2025
  6. ogrisel commented on Mar 21, 2025

    @ogrisel
    Member

    Happy to add a 'generate ID' function, if others don't think its adding too much complexity

    I don't have a better solution to propose... and the current status quo is really misleading, so probably worth fixing.

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