|
11 | 11 | except ImportError: |
12 | 12 | from funcsigs import signature, Parameter # noqa |
13 | 13 |
|
| 14 | +try: # native coroutines, python 3.5+ |
| 15 | + from inspect import iscoroutinefunction |
| 16 | +except ImportError: |
| 17 | + def iscoroutinefunction(obj): |
| 18 | + return False |
| 19 | + |
| 20 | +try: # native async generators, python 3.6+ |
| 21 | + from inspect import isasyncgenfunction |
| 22 | +except ImportError: |
| 23 | + def isasyncgenfunction(obj): |
| 24 | + return False |
| 25 | + |
14 | 26 | try: |
15 | 27 | from collections.abc import Iterable |
16 | 28 | except ImportError: # noqa |
|
25 | 37 | pass |
26 | 38 |
|
27 | 39 | import pytest |
| 40 | +import sys |
28 | 41 | from makefun import with_signature, remove_signature_parameters, add_signature_parameters, wraps |
29 | 42 |
|
30 | 43 | from .common_mini_six import string_types |
@@ -1059,30 +1072,44 @@ def replace_paramfixture_with_values(kwargs): # noqa |
1059 | 1072 | # return |
1060 | 1073 | return kwargs |
1061 | 1074 |
|
1062 | | - if not isgeneratorfunction(test_func): |
1063 | | - # normal test or fixture function with return statement |
1064 | | - @wraps(test_func, new_sig=new_sig) |
1065 | | - def wrapped_test_func(*args, **kwargs): # noqa |
1066 | | - if kwargs.get(fixture_union_name, None) is NOT_USED: |
1067 | | - # TODO why this ? it is probably useless: this fixture |
1068 | | - # is private and will never end up in another union |
1069 | | - return NOT_USED |
1070 | | - else: |
1071 | | - replace_paramfixture_with_values(kwargs) |
1072 | | - return test_func(*args, **kwargs) |
1073 | 1075 |
|
| 1076 | + if isasyncgenfunction(test_func)and sys.version_info >= (3, 6): |
| 1077 | + from .pep525 import _parametrize_plus_decorate_asyncgen_pep525 |
| 1078 | + wrapped_test_func = _parametrize_plus_decorate_asyncgen_pep525(test_func, new_sig, fixture_union_name, |
| 1079 | + replace_paramfixture_with_values) |
| 1080 | + elif iscoroutinefunction(test_func) and sys.version_info >= (3, 5): |
| 1081 | + from .pep492 import _parametrize_plus_decorate_coroutine_pep492 |
| 1082 | + wrapped_test_func = _parametrize_plus_decorate_coroutine_pep492(test_func, new_sig, fixture_union_name, |
| 1083 | + replace_paramfixture_with_values) |
| 1084 | + elif isgeneratorfunction(test_func): |
| 1085 | + # generator function (with a yield statement) |
| 1086 | + if sys.version_info >= (3, 3): |
| 1087 | + from .pep380 import _parametrize_plus_decorate_generator_pep380 |
| 1088 | + wrapped_test_func = _parametrize_plus_decorate_generator_pep380(test_func, new_sig, |
| 1089 | + fixture_union_name, |
| 1090 | + replace_paramfixture_with_values) |
| 1091 | + else: |
| 1092 | + @wraps(test_func, new_sig=new_sig) |
| 1093 | + def wrapped_test_func(*args, **kwargs): # noqa |
| 1094 | + if kwargs.get(fixture_union_name, None) is NOT_USED: |
| 1095 | + # TODO why this ? it is probably useless: this fixture |
| 1096 | + # is private and will never end up in another union |
| 1097 | + yield NOT_USED |
| 1098 | + else: |
| 1099 | + replace_paramfixture_with_values(kwargs) |
| 1100 | + for res in test_func(*args, **kwargs): |
| 1101 | + yield res |
1074 | 1102 | else: |
1075 | | - # generator test or fixture function (with one or several yield statements) |
| 1103 | + # normal function with return statement |
1076 | 1104 | @wraps(test_func, new_sig=new_sig) |
1077 | 1105 | def wrapped_test_func(*args, **kwargs): # noqa |
1078 | 1106 | if kwargs.get(fixture_union_name, None) is NOT_USED: |
1079 | 1107 | # TODO why this ? it is probably useless: this fixture |
1080 | 1108 | # is private and will never end up in another union |
1081 | | - yield NOT_USED |
| 1109 | + return NOT_USED |
1082 | 1110 | else: |
1083 | 1111 | replace_paramfixture_with_values(kwargs) |
1084 | | - for res in test_func(*args, **kwargs): |
1085 | | - yield res |
| 1112 | + return test_func(*args, **kwargs) |
1086 | 1113 |
|
1087 | 1114 | # move all pytest marks from the test function to the wrapper |
1088 | 1115 | # not needed because the __dict__ is automatically copied when we use @wraps |
|
0 commit comments