Small cleanups on _pytest.compat

Small improvements and cleanups
This commit is contained in:
Bruno Oliveira
2019-06-15 10:06:37 -03:00
parent 240828d912
commit 355eb5adfb
5 changed files with 25 additions and 30 deletions

View File

@@ -23,8 +23,6 @@ from _pytest.compat import getfslineno
from _pytest.compat import getimfunc
from _pytest.compat import getlocation
from _pytest.compat import is_generator
from _pytest.compat import isclass
from _pytest.compat import isfunction
from _pytest.compat import NOTSET
from _pytest.compat import REGEX_TYPE
from _pytest.compat import safe_getattr
@@ -207,7 +205,7 @@ def pytest_pycollect_makeitem(collector, name, obj):
# We need to try and unwrap the function if it's a functools.partial
# or a funtools.wrapped.
# We musn't if it's been wrapped with mock.patch (python 2 only)
if not (isfunction(obj) or isfunction(get_real_func(obj))):
if not (inspect.isfunction(obj) or inspect.isfunction(get_real_func(obj))):
filename, lineno = getfslineno(obj)
warnings.warn_explicit(
message=PytestCollectionWarning(
@@ -1190,7 +1188,7 @@ def _idval(val, argname, idx, idfn, item, config):
return ascii_escaped(val.pattern)
elif enum is not None and isinstance(val, enum.Enum):
return str(val)
elif (isclass(val) or isfunction(val)) and hasattr(val, "__name__"):
elif (inspect.isclass(val) or inspect.isfunction(val)) and hasattr(val, "__name__"):
return val.__name__
return str(argname) + str(idx)