Use repr() for unknown objects in utils.qualname.

This commit is contained in:
Florian Bruhin 2015-06-17 06:46:03 +02:00
parent dfe98d1053
commit b1334bcc22
2 changed files with 5 additions and 2 deletions

View File

@ -553,7 +553,7 @@ def qualname(obj):
elif hasattr(obj, '__name__'):
name = obj.__name__
else:
name = '<unknown>'
name = repr(obj)
if inspect.isclass(obj) or inspect.isfunction(obj):
module = obj.__module__

View File

@ -721,8 +721,11 @@ def qualname_func(_blah):
pass
QUALNAME_OBJ = QualnameObj()
@pytest.mark.parametrize('obj, expected', [
(QualnameObj(), '<unknown>'), # instance - unknown
(QUALNAME_OBJ, repr(QUALNAME_OBJ)), # instance - unknown
(QualnameObj, 'test_utils.QualnameObj'), # class
(QualnameObj.func, 'test_utils.QualnameObj.func'), # unbound method
(QualnameObj().func, 'test_utils.QualnameObj.func'), # bound method