Helper function for creating new test functions for each parameterized form. :param name: the original name of the function :param func: the original function that we are parameterizing :param suffix: the suffix to append to the name of the function for this parameterization :param
(mcs, name, func, suffix, args)
| 385 | class RunnerMeta(type): |
| 386 | @classmethod |
| 387 | def make_test(mcs, name, func, suffix, args): |
| 388 | """Helper function for creating new test functions for each parameterized form. |
| 389 | |
| 390 | :param name: the original name of the function |
| 391 | :param func: the original function that we are parameterizing |
| 392 | :param suffix: the suffix to append to the name of the function for this parameterization |
| 393 | :param args: the positional arguments to pass to the original function for this parameterization |
| 394 | :returns: a tuple of (new_function_name, new_function_object) |
| 395 | """ |
| 396 | |
| 397 | # Create the new test function. It calls the original function with the specified args. |
| 398 | # We use @functools.wraps to copy over all the function attributes. |
| 399 | @wraps(func) |
| 400 | def resulting_test(self): |
| 401 | return func(self, *args) |
| 402 | |
| 403 | # Add suffix to the function name so that it displays correctly. |
| 404 | if suffix: |
| 405 | resulting_test.__name__ = f'{name}_{suffix}' |
| 406 | else: |
| 407 | resulting_test.__name__ = name |
| 408 | |
| 409 | # On python 3, functions have __qualname__ as well. This is a full dot-separated path to the |
| 410 | # function. We add the suffix to it as well. |
| 411 | resulting_test.__qualname__ = f'{func.__qualname__}_{suffix}' |
| 412 | |
| 413 | return resulting_test.__name__, resulting_test |
| 414 | |
| 415 | def __new__(mcs, name, bases, attrs): |
| 416 | # This metaclass expands parameterized methods from `attrs` into separate ones in `new_attrs`. |