Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

None in paramtrized test id will use automatically generated id #1468

Next Next commit
allow None to be passed in ids list for specific test and recieve idm…
…aker name for test
  • Loading branch information
palaviv committed Mar 19, 2016
commit be1954afbcec9f9470a0a9dfbfe09f025ce78ddf
18 changes: 10 additions & 8 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,7 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
if ids and len(ids) != len(argvalues):
raise ValueError('%d tests specified with %d ids' %(
len(argvalues), len(ids)))
if not ids:
ids = idmaker(argnames, argvalues, idfn)
ids = idmaker(argnames, argvalues, idfn, ids)
newcalls = []
for callspec in self._calls or [CallSpec2(self)]:
for param_index, valset in enumerate(argvalues):
Expand Down Expand Up @@ -1130,13 +1129,16 @@ def _idval(val, argname, idx, idfn):
pass
return str(argname)+str(idx)

def _idvalset(idx, valset, argnames, idfn):
this_id = [_idval(val, argname, idx, idfn)
for val, argname in zip(valset, argnames)]
return "-".join(this_id)
def _idvalset(idx, valset, argnames, idfn, ids):
if ids is None or ids[idx] is None:
this_id = [_idval(val, argname, idx, idfn)
for val, argname in zip(valset, argnames)]
return "-".join(this_id)
else:
return ids[idx]

def idmaker(argnames, argvalues, idfn=None):
ids = [_idvalset(valindex, valset, argnames, idfn)
def idmaker(argnames, argvalues, idfn=None, ids=None):
ids = [_idvalset(valindex, valset, argnames, idfn, ids)
for valindex, valset in enumerate(argvalues)]
if len(set(ids)) < len(ids):
# user may have provided a bad idfn which means the ids are not unique
Expand Down