Class decorator to register a test class. The test class must have: - A class attribute `name` (str) - the base test name - A class method `get_test_configs()` that returns a list of OpTestCase instances Test instances are created LAZILY when tests are actually run, not at imp
(test_class: type)
| 751 | |
| 752 | |
| 753 | def register_test(test_class: type) -> type: |
| 754 | """ |
| 755 | Class decorator to register a test class. |
| 756 | |
| 757 | The test class must have: |
| 758 | - A class attribute `name` (str) - the base test name |
| 759 | - A class method `get_test_configs()` that returns a list of OpTestCase instances |
| 760 | |
| 761 | Test instances are created LAZILY when tests are actually run, not at import time. |
| 762 | This avoids creating random tensors at import time and keeps memory usage low. |
| 763 | |
| 764 | Example: |
| 765 | @register_test |
| 766 | class AddTest(OpTestCase): |
| 767 | name = "add" |
| 768 | |
| 769 | @classmethod |
| 770 | def get_test_configs(cls) -> List["OpTestCase"]: |
| 771 | return [ |
| 772 | cls(), # default config |
| 773 | cls(scalar=2.5), # scalar variant |
| 774 | ] |
| 775 | """ |
| 776 | if not hasattr(test_class, "name"): |
| 777 | raise ValueError( |
| 778 | f"Test class {test_class.__name__} must have a 'name' attribute" |
| 779 | ) |
| 780 | |
| 781 | base_name = test_class.name |
| 782 | _TEST_REGISTRY[base_name] = test_class |
| 783 | |
| 784 | return test_class |
| 785 | |
| 786 | |
| 787 | def get_registered_tests() -> Dict[str, List[Tuple[str, "OpTestCase"]]]: |