Skip to content

Test classes should extend common_utils.TestCase vs vanilla TestCase #66903

@janeyx99

Description

@janeyx99

There are many cases where unittest.TestCase is extended today instead of our specialized common_utils.TestCase in our code base, like in many distributed tests, fx tests, and onnx tests:

https://github.com/pytorch/pytorch/search?q=Unittest.TestCase

Sometimes, this is intentional, but often times, I suspect it is accidental or due to oversight/unawareness. These test cases miss out on the customizations we place in https://github.com/pytorch/pytorch/blob/master/torch/testing/_internal/common_utils.py#L1307, which include:

  • Not enjoying the functionality of pre-written wrappers
  • The CI not being able to check and skip if they are a slow test
  • The CI not being able to check and skip if they are disabled

To enforce this, we can check in run_tests() if the test is a vanilla unittest.TestCase and error when that is the case. This would capture the case where the test writer is trying to use all the features in common_utils.py but neglected to extend the right TestCase. This would also allow test classes that intend to use the vanilla TestCase to do so without being yelled at.

cc @seemethere @malfet @pytorch/pytorch-dev-infra

Metadata

Metadata

Assignees

No one assigned

    Labels

    actionablebetter-engineeringRelatively self-contained tasks for better engineering contributorsmodule: ciRelated to continuous integrationtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions