@@ -879,7 +879,13 @@ def get_current_cases(request_or_item):
879879 argval = LazyTupleItem (argvals , item )
880880 _possibly_add_cases_to_results (request , fix_results , mp_fix_to_args , argname , argval )
881881 else :
882- print ()
882+ # not lazy = normal parameter = there is no way this is a case
883+ pass
884+
885+ # cleanup: delete the empty subdict if the params were not cases.
886+ if len (fix_results ) == 0 :
887+ del results [argname_or_fixturename ]
888+
883889
884890 # (2) Parameters on a test function, or parameters on a fixture with a fixture_ref inside (other fixture gen)
885891 else :
@@ -944,9 +950,18 @@ def _possibly_add_cases_to_results(request, results, mp_fix_to_args, argname_or_
944950 return
945951
946952 # If the parametrization target is not the test but a fixture, store the cases in a dub-dict
953+ orig_results = None
947954 if parametrized is not None and parametrized .__name__ != request .node .function .__name__ :
955+ # store the wrapping dict because we'll delete this entry in the end if it is empty
956+ orig_results = results
948957 results = _get_or_create_subdict (results , parametrized .__name__ )
949958
959+ # this function will need to be called before returning
960+ def _cleanup_before_return ():
961+ # remove the subdict if it was created for nothing
962+ if orig_results is not None and len (results ) == 0 :
963+ del orig_results [parametrized .__name__ ]
964+
950965 # If we did not yet find the case function, this is because this was a simple parametrize without fixture ref.
951966 if case_func is None :
952967 if isinstance (current_param_value , LazyTupleItem ):
@@ -964,10 +979,12 @@ def _possibly_add_cases_to_results(request, results, mp_fix_to_args, argname_or_
964979
965980 elif current_param_value in (NOT_USED , USED ):
966981 # ignore silently
982+ _cleanup_before_return ()
967983 return
968984 else :
969985 # raise TypeError("Internal error - type not expected : %r" % type(current_param_value))
970986 # some other parameter - return silently
987+ _cleanup_before_return ()
971988 return
972989
973990 # Finally do it
@@ -981,6 +998,8 @@ def _possibly_add_cases_to_results(request, results, mp_fix_to_args, argname_or_
981998 raise ValueError ("Internal error - please report" )
982999 results [argname ] = (actual_id , case_func )
9831000
1001+ _cleanup_before_return ()
1002+
9841003
9851004def _get_or_create_subdict (dct , key ):
9861005 try :
0 commit comments