Skip to content

test: subTest creates more problems than it solves with pytest >=9 #637

Open

Description

@cpcloud

As of pytest 9 with pytest-xdist, the subTest method of unittest.TestCase now runs subtests across processes. This creates a requirement that subtest inputs must be process-serializable, which isn't satisified for various numba types.

A solution to this problem is to move towards pytest.mark.parametrize, which has no such requirement. I looked at our subTest usage, and AFAICT all of it parametrizes over static values, meaning it's a straightforward conversion.

The annoying thing is pytest will not parametrize unittest.TestCase test methods subclasses, only methods of classes that are not subclasses of TestCase.

I think this means that we need to move away from TestCase subclasses entirely, and unittest as well.

I think we can do this by moving the CUDATestCase setup and teardown to session/module/function fixtures as needed, and move the methods that it has to top level functions that can be imported from conftest.py.

Activity

  1. cpcloud commented on Dec 5, 2025

    @cpcloud
    ContributorAuthor

    For now, I'm going to set an upper bound on pytest to <9 so that we can continue to update other dependencies.

  2. gmarkall commented on Dec 5, 2025

    @gmarkall
    Contributor

    See also #619. I think there is an extension that allows parametrization of test classes: https://github.com/adamchainz/unittest-parametrize but I don't yet have a perspective on whether it's worth introducing instead of just converting the test suite to pytest.

  3. cpcloud commented on Dec 5, 2025

    @cpcloud
    ContributorAuthor

    I think we can preserve most of the test suite structure (e.g., not rewriting everything to function tests instead of classes) without that plugin.

    That said, I don't think it ultimately matters that much since if we have to move away from subtest, then adding a new plugin that has the equivalent behavior to pytest.mark.parametrize seems like approximately the same amount of work as using the native decorator.

  4. cpcloud commented on Dec 5, 2025

    @cpcloud
    ContributorAuthor

    In which case, not adding a dependency seems preferable.

  5. added this to the v0.23.0 milestone on Dec 17, 2025
  6. modified the milestones: v0.25.0, next on Feb 10, 2026
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions