Unverified Commit d2724481 authored by moto's avatar moto Committed by GitHub
Browse files

Change parameterized testing system to be compatible with unittest (#712)



* Change parameterized testing system to be compatible with unittest

Summary: The previous implementation of parameterized testing worked by modifying test.common_utils inplace.  This doesn't work in general because unittest's contract with test modules is such that it must be able to load the module and run the test itself.  Because the previous implementation needed to load the module and modify it, it is incompatible.

Reviewed By: mthrok

Differential Revision: D21964676
Co-authored-by: default avatarBen Mehne <bmehne@fb.com>
parent 55b5c80c
......@@ -119,6 +119,15 @@ def define_test_suites(
scope[t.__name__] = t
def common_test_class_parameters(
dtypes: Iterable[str] = ("float32", "float64"),
devices: Iterable[str] = ("cpu", "cuda"),
):
for device in devices:
for dtype in dtypes:
yield {"device": torch.device(device), "dtype": getattr(torch, dtype)}
def get_whitenoise(
*,
sample_rate: int = 16000,
......
from .common_utils import define_test_suites
from parameterized import parameterized_class
from .common_utils import TestCase, common_test_class_parameters
from .torchscript_consistency_impl import Functional, Transforms
define_test_suites(globals(), [Functional, Transforms], devices=['cpu'])
parameters = list(common_test_class_parameters(devices=['cpu']))
@parameterized_class(parameters)
class TestFunctional(Functional, TestCase):
pass
@parameterized_class(parameters)
class TestTransforms(Transforms, TestCase):
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment