forked from man-group/pytest-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpytest_verbose_parametrize.py
35 lines (31 loc) · 1.09 KB
/
pytest_verbose_parametrize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from collections import Iterable
from six import string_types
def _strize_arg(arg):
try:
s = arg.__name__
except AttributeError:
s = str(arg)
if len(s) > 32:
s = s[:29] + '...'
return s
def pytest_generate_tests(metafunc):
try:
markers = metafunc.function.parametrize
except AttributeError:
return
if 'ids' not in markers.kwargs:
list_names = []
for i, argvalue in enumerate(markers.args[1]):
if (not isinstance(argvalue, Iterable)) or isinstance(argvalue, string_types):
argvalue = (argvalue,)
name = '-'.join(_strize_arg(arg) for arg in argvalue)
if len(name) > 64:
name = name[:61] + '...'
while name in list_names:
name = '%s#%d' % (name, i)
list_names.append(name)
markers.kwargs['ids'] = list_names
# In pytest versions pre-3.1.0 MarkInfo copies the
# kwargs into an internal variable as well :/
if hasattr(markers, '_arglist'):
markers._arglist[0][-1]['ids'] = list_names