@@ -342,6 +342,9 @@ def pytest_pycollect_makeitem(collector, name, obj):
342
342
res = list (collector ._genfunctions (name , obj ))
343
343
outcome .force_result (res )
344
344
345
+ def pytest_make_parametrize_id (val ):
346
+ return None
347
+
345
348
def is_generator (func ):
346
349
try :
347
350
return _pytest ._code .getrawcode (func ).co_flags & 32 # generator function
@@ -1030,7 +1033,7 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
1030
1033
if ids and len (ids ) != len (argvalues ):
1031
1034
raise ValueError ('%d tests specified with %d ids' % (
1032
1035
len (argvalues ), len (ids )))
1033
- ids = idmaker (argnames , argvalues , idfn , ids )
1036
+ ids = idmaker (argnames , argvalues , idfn , ids , self . config )
1034
1037
newcalls = []
1035
1038
for callspec in self ._calls or [CallSpec2 (self )]:
1036
1039
for param_index , valset in enumerate (argvalues ):
@@ -1130,7 +1133,7 @@ def _escape_strings(val):
1130
1133
return val .encode ('unicode-escape' )
1131
1134
1132
1135
1133
- def _idval (val , argname , idx , idfn ):
1136
+ def _idval (val , argname , idx , idfn , config ):
1134
1137
if idfn :
1135
1138
try :
1136
1139
s = idfn (val )
@@ -1139,6 +1142,11 @@ def _idval(val, argname, idx, idfn):
1139
1142
except Exception :
1140
1143
pass
1141
1144
1145
+ if config :
1146
+ hook_id = config .hook .pytest_make_parametrize_id (val = val )
1147
+ if hook_id :
1148
+ return hook_id
1149
+
1142
1150
if isinstance (val , (bytes , str )) or (_PY2 and isinstance (val , unicode )):
1143
1151
return _escape_strings (val )
1144
1152
elif isinstance (val , (float , int , bool , NoneType )):
@@ -1151,16 +1159,16 @@ def _idval(val, argname, idx, idfn):
1151
1159
return val .__name__
1152
1160
return str (argname )+ str (idx )
1153
1161
1154
- def _idvalset (idx , valset , argnames , idfn , ids ):
1162
+ def _idvalset (idx , valset , argnames , idfn , ids , config ):
1155
1163
if ids is None or ids [idx ] is None :
1156
- this_id = [_idval (val , argname , idx , idfn )
1164
+ this_id = [_idval (val , argname , idx , idfn , config )
1157
1165
for val , argname in zip (valset , argnames )]
1158
1166
return "-" .join (this_id )
1159
1167
else :
1160
1168
return _escape_strings (ids [idx ])
1161
1169
1162
- def idmaker (argnames , argvalues , idfn = None , ids = None ):
1163
- ids = [_idvalset (valindex , valset , argnames , idfn , ids )
1170
+ def idmaker (argnames , argvalues , idfn = None , ids = None , config = None ):
1171
+ ids = [_idvalset (valindex , valset , argnames , idfn , ids , config )
1164
1172
for valindex , valset in enumerate (argvalues )]
1165
1173
if len (set (ids )) != len (ids ):
1166
1174
# The ids are not unique
0 commit comments