@@ -890,7 +890,7 @@ def _cleanup_calls_list(metafunc, fix_closure_tree, calls, nodes, pending):
890890 if nb_calls != len (nodes ):
891891 raise ValueError ("This should not happen !" )
892892
893- # function_scope_num = get_pytest_function_scopenum()
893+ function_scope_num = get_pytest_function_scopenum ()
894894
895895 for i in range (nb_calls ):
896896 c , n = calls [i ], nodes [i ]
@@ -921,17 +921,16 @@ def _cleanup_calls_list(metafunc, fix_closure_tree, calls, nodes, pending):
921921 #
922922 # For this we use a dirty hack: we add a parameter with they name in the callspec, it seems to be propagated
923923 # in the `request`. TODO is there a better way?
924- f_scope = get_pytest_function_scopenum ()
925924 for fixture_name in fix_closure_tree .get_not_always_used ():
925+ # (a) retrieve fixture scope
926926 try :
927927 fixdef = metafunc ._arg2fixturedefs [fixture_name ] # noqa
928928 except KeyError :
929929 continue # dont raise any error here and let pytest say "not found"
930-
931930 this_scopenum = fixdef [- 1 ].scopenum
932931
933- # only do this for function-scoped fixtures, module or session scoped fixtures should remain active
934- if this_scopenum == f_scope :
932+ # (b) only do this for function-scoped fixtures, module or session scoped fixtures should remain active
933+ if this_scopenum == function_scope_num :
935934 if fixture_name not in c .params and fixture_name not in c .funcargs :
936935 if not n .requires (fixture_name ):
937936 # explicitly add it as discarded by creating a parameter value for it.
@@ -944,6 +943,18 @@ def _cleanup_calls_list(metafunc, fix_closure_tree, calls, nodes, pending):
944943 c .indices [fixture_name ] = 0
945944 c ._arg2scopenum [fixture_name ] = this_scopenum # get_pytest_scopenum(fixdef[-1].scope) # noqa
946945
946+ # finally, if there are some session or module-scoped fixtures that
947+ # are used in *none* of the calls, they could be deactivated too
948+ # (see https://github.com/smarie/python-pytest-cases/issues/137)
949+ #
950+ # for fixture_name in fix_closure_tree.get_not_always_used():
951+ # # (a) retrieve fixture scope
952+ # ...
953+ # # (b) for non function-scoped fixtures
954+ # if this_scopenum != function_scope_num:
955+ # # to do check if there is at least one call that actually uses the fixture and is not skipped...
956+ # # this seems a bit "too much" !! > WONT FIX
957+
947958
948959# def get_calls_for_partition(metafunc, super_closure, p_idx, pending):
949960# """
0 commit comments