|
28 | 28 |
|
29 | 29 | from .common_mini_six import string_types |
30 | 30 | from .common_pytest_lazy_values import get_lazy_args |
31 | | -from .common_pytest_marks import PYTEST35_OR_GREATER, PYTEST46_OR_GREATER, PYTEST37_OR_GREATER |
32 | | -from .common_pytest import get_pytest_nodeid, get_pytest_function_scopenum, is_function_node, get_param_names, \ |
33 | | - get_param_argnames_as_list |
| 31 | +from .common_pytest_marks import PYTEST35_OR_GREATER, PYTEST46_OR_GREATER, PYTEST37_OR_GREATER, PYTEST7_OR_GREATER |
| 32 | +from .common_pytest import get_pytest_nodeid, get_pytest_function_scopeval, is_function_node, get_param_names, \ |
| 33 | + get_param_argnames_as_list, has_function_scope, set_callspec_arg_scope_to_function |
34 | 34 |
|
35 | 35 | from .fixture_core1_unions import NOT_USED, USED, is_fixture_union_params, UnionFixtureAlternative |
36 | 36 |
|
@@ -187,12 +187,22 @@ def get_all_fixture_defs(self, drop_fake_fixtures=True, try_to_sort=True): |
187 | 187 | items = self.gen_all_fixture_defs(drop_fake_fixtures=drop_fake_fixtures) |
188 | 188 |
|
189 | 189 | # sort by scope as in pytest fixture closure creator (pytest did not do it in early versions, align with this) |
190 | | - if try_to_sort and PYTEST35_OR_GREATER: |
191 | | - f_scope = get_pytest_function_scopenum() |
192 | | - def sort_by_scope(kv_pair): # noqa |
193 | | - fixture_name, fixture_defs = kv_pair |
194 | | - return fixture_defs[-1].scopenum if fixture_defs is not None else f_scope |
195 | | - items = sorted(list(items), key=sort_by_scope) |
| 190 | + if try_to_sort: |
| 191 | + if PYTEST7_OR_GREATER: |
| 192 | + # Scope is an enum, values are in reversed order, and the field is _scope |
| 193 | + f_scope = get_pytest_function_scopeval() |
| 194 | + def sort_by_scope(kv_pair): |
| 195 | + fixture_name, fixture_defs = kv_pair |
| 196 | + return fixture_defs[-1]._scope if fixture_defs is not None else f_scope |
| 197 | + items = sorted(list(items), key=sort_by_scope, reverse=True) |
| 198 | + |
| 199 | + elif PYTEST35_OR_GREATER: |
| 200 | + # scopes is a list, values are indices in the list, and the field is scopenum |
| 201 | + f_scope = get_pytest_function_scopeval() |
| 202 | + def sort_by_scope(kv_pair): # noqa |
| 203 | + fixture_name, fixture_defs = kv_pair |
| 204 | + return fixture_defs[-1].scopenum if fixture_defs is not None else f_scope |
| 205 | + items = sorted(list(items), key=sort_by_scope) |
196 | 206 |
|
197 | 207 | return OrderedDict(items) |
198 | 208 |
|
@@ -562,7 +572,7 @@ def _update_fixture_defs(self): |
562 | 572 |
|
563 | 573 | # # also sort all partitions (note that we cannot rely on the order in all_fixture_defs when scopes are same!) |
564 | 574 | # if LooseVersion(pytest.__version__) >= LooseVersion('3.5.0'): |
565 | | - # f_scope = get_pytest_function_scopenum() |
| 575 | + # f_scope = get_pytest_function_scopeval() |
566 | 576 | # for p in self.partitions: |
567 | 577 | # def sort_by_scope2(fixture_name): # noqa |
568 | 578 | # fixture_defs = all_fixture_defs[fixture_name] |
@@ -1031,14 +1041,13 @@ def _cleanup_calls_list(metafunc, |
1031 | 1041 | # create ref lists of fixtures per scope |
1032 | 1042 | _not_always_used_func_scoped = [] |
1033 | 1043 | # _not_always_used_other_scoped = [] |
1034 | | - _function_scope_num = get_pytest_function_scopenum() |
1035 | 1044 | for fixture_name in fix_closure_tree.get_not_always_used(): |
1036 | 1045 | try: |
1037 | 1046 | fixdef = metafunc._arg2fixturedefs[fixture_name] # noqa |
1038 | 1047 | except KeyError: |
1039 | 1048 | continue # dont raise any error here and let pytest say "not found" later |
1040 | 1049 | else: |
1041 | | - if fixdef[-1].scopenum == _function_scope_num: |
| 1050 | + if has_function_scope(fixdef[-1]): |
1042 | 1051 | _not_always_used_func_scoped.append(fixture_name) |
1043 | 1052 | # else: |
1044 | 1053 | # _not_always_used_other_scoped.append(fixture_name) |
@@ -1078,12 +1087,12 @@ def _cleanup_calls_list(metafunc, |
1078 | 1087 | # explicitly add it as discarded by creating a parameter value for it. |
1079 | 1088 | c.params[fixture_name] = NOT_USED |
1080 | 1089 | c.indices[fixture_name] = 1 |
1081 | | - c._arg2scopenum[fixture_name] = _function_scope_num # get_pytest_scopenum(fixdef[-1].scope) # noqa |
| 1090 | + set_callspec_arg_scope_to_function(c, fixture_name) |
1082 | 1091 | else: |
1083 | 1092 | # explicitly add it as active |
1084 | 1093 | c.params[fixture_name] = USED |
1085 | 1094 | c.indices[fixture_name] = 0 |
1086 | | - c._arg2scopenum[fixture_name] = _function_scope_num # get_pytest_scopenum(fixdef[-1].scope) # noqa |
| 1095 | + set_callspec_arg_scope_to_function(c, fixture_name) |
1087 | 1096 |
|
1088 | 1097 | # finally, if there are some session or module-scoped fixtures that |
1089 | 1098 | # are used in *none* of the calls, they could be deactivated too |
|
0 commit comments