Merge pull request #2976 from st--/master
Extend _pytest.python._idval to return __name__ of functions as well
This commit is contained in:
commit
294729962d
|
@ -933,7 +933,7 @@ def _idval(val, argname, idx, idfn, config=None):
|
|||
return ascii_escaped(val.pattern)
|
||||
elif enum is not None and isinstance(val, enum.Enum):
|
||||
return str(val)
|
||||
elif isclass(val) and hasattr(val, '__name__'):
|
||||
elif (isclass(val) or isfunction(val)) and hasattr(val, '__name__'):
|
||||
return val.__name__
|
||||
return str(argname) + str(idx)
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Change parametrized automatic test id generation to use the ``__name__`` attribute of functions instead of the fallback argument name plus counter.
|
|
@ -235,6 +235,25 @@ class TestMetafunc(object):
|
|||
for val, expected in values:
|
||||
assert _idval(val, 'a', 6, None) == expected
|
||||
|
||||
def test_class_or_function_idval(self):
|
||||
"""unittest for the expected behavior to obtain ids for parametrized
|
||||
values that are classes or functions: their __name__.
|
||||
"""
|
||||
from _pytest.python import _idval
|
||||
|
||||
class TestClass:
|
||||
pass
|
||||
|
||||
def test_function():
|
||||
pass
|
||||
|
||||
values = [
|
||||
(TestClass, "TestClass"),
|
||||
(test_function, "test_function"),
|
||||
]
|
||||
for val, expected in values:
|
||||
assert _idval(val, 'a', 6, None) == expected
|
||||
|
||||
@pytest.mark.issue250
|
||||
def test_idmaker_autoname(self):
|
||||
from _pytest.python import idmaker
|
||||
|
|
Loading…
Reference in New Issue