Execute the decorated test only if a GPU is available. This function is intended to be applied to tests that require the presence of a GPU. If a GPU is absent, it will simply be skipped. Args: func: function to be annotated. If `func` is None, this method returns a decorator the ca
(func=None)
| 1318 | |
| 1319 | |
| 1320 | def run_gpu_only(func=None): |
| 1321 | """Execute the decorated test only if a GPU is available. |
| 1322 | |
| 1323 | This function is intended to be applied to tests that require the presence |
| 1324 | of a GPU. If a GPU is absent, it will simply be skipped. |
| 1325 | |
| 1326 | Args: |
| 1327 | func: function to be annotated. If `func` is None, this method returns a |
| 1328 | decorator the can be applied to a function. If `func` is not None this |
| 1329 | returns the decorator applied to `func`. |
| 1330 | |
| 1331 | Returns: |
| 1332 | Returns a decorator that will conditionally skip the decorated test method. |
| 1333 | """ |
| 1334 | |
| 1335 | def decorator(f): |
| 1336 | if tf_inspect.isclass(f): |
| 1337 | raise ValueError("`run_gpu_only` only supports test methods.") |
| 1338 | |
| 1339 | def decorated(self, *args, **kwargs): |
| 1340 | if not is_gpu_available(): |
| 1341 | self.skipTest("Test requires GPU") |
| 1342 | |
| 1343 | return f(self, *args, **kwargs) |
| 1344 | |
| 1345 | return decorated |
| 1346 | |
| 1347 | if func is not None: |
| 1348 | return decorator(func) |
| 1349 | |
| 1350 | return decorator |
| 1351 | |
| 1352 | |
| 1353 | def run_cuda_only(func=None): |
nothing calls this directly
no test coverage detected