1
1
""" Python test discovery, setup and run of test functions. """
2
- import collections
3
2
import enum
4
3
import fnmatch
5
4
import inspect
6
5
import os
7
6
import sys
8
7
import warnings
8
+ from collections import Counter
9
+ from collections .abc import Sequence
9
10
from functools import partial
10
11
from textwrap import dedent
11
12
@@ -1042,12 +1043,9 @@ def _resolve_arg_value_types(self, argnames, indirect):
1042
1043
* "params" if the argname should be the parameter of a fixture of the same name.
1043
1044
* "funcargs" if the argname should be a parameter to the parametrized test function.
1044
1045
"""
1045
- valtypes = {}
1046
- if indirect is True :
1047
- valtypes = dict .fromkeys (argnames , "params" )
1048
- elif indirect is False :
1049
- valtypes = dict .fromkeys (argnames , "funcargs" )
1050
- elif isinstance (indirect , (tuple , list )):
1046
+ if isinstance (indirect , bool ):
1047
+ valtypes = dict .fromkeys (argnames , "params" if indirect else "funcargs" )
1048
+ elif isinstance (indirect , Sequence ):
1051
1049
valtypes = dict .fromkeys (argnames , "funcargs" )
1052
1050
for arg in indirect :
1053
1051
if arg not in argnames :
@@ -1058,6 +1056,13 @@ def _resolve_arg_value_types(self, argnames, indirect):
1058
1056
pytrace = False ,
1059
1057
)
1060
1058
valtypes [arg ] = "params"
1059
+ else :
1060
+ fail (
1061
+ "In {func}: expected Sequence or boolean for indirect, got {type}" .format (
1062
+ type = type (indirect ).__name__ , func = self .function .__name__
1063
+ ),
1064
+ pytrace = False ,
1065
+ )
1061
1066
return valtypes
1062
1067
1063
1068
def _validate_if_using_arg_names (self , argnames , indirect ):
@@ -1185,7 +1190,7 @@ def idmaker(argnames, parametersets, idfn=None, ids=None, config=None, item=None
1185
1190
if len (set (ids )) != len (ids ):
1186
1191
# The ids are not unique
1187
1192
duplicates = [testid for testid in ids if ids .count (testid ) > 1 ]
1188
- counters = collections . defaultdict ( lambda : 0 )
1193
+ counters = Counter ( )
1189
1194
for index , testid in enumerate (ids ):
1190
1195
if testid in duplicates :
1191
1196
ids [index ] = testid + str (counters [testid ])
0 commit comments