Use functools.partial name explicitly and simplify the code a bit as asked in review
This commit is contained in:
parent
dcdc823dd2
commit
a7b4ed89da
|
@ -1,5 +1,6 @@
|
||||||
""" Python test discovery, setup and run of test functions. """
|
""" Python test discovery, setup and run of test functions. """
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import functools
|
||||||
import py
|
import py
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
@ -24,7 +25,7 @@ def get_real_func(obj):
|
||||||
"""
|
"""
|
||||||
while hasattr(obj, "__wrapped__"):
|
while hasattr(obj, "__wrapped__"):
|
||||||
obj = obj.__wrapped__
|
obj = obj.__wrapped__
|
||||||
if isinstance(obj, py.std.functools.partial):
|
if isinstance(obj, functools.partial):
|
||||||
obj = obj.func
|
obj = obj.func
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@ -603,10 +604,7 @@ class FunctionMixin(PyobjMixin):
|
||||||
|
|
||||||
def _prunetraceback(self, excinfo):
|
def _prunetraceback(self, excinfo):
|
||||||
if hasattr(self, '_obj') and not self.config.option.fulltrace:
|
if hasattr(self, '_obj') and not self.config.option.fulltrace:
|
||||||
if isinstance(self.obj, py.std.functools.partial):
|
code = py.code.Code(get_real_func(self.obj))
|
||||||
code = py.code.Code(self.obj.func)
|
|
||||||
else:
|
|
||||||
code = py.code.Code(self.obj)
|
|
||||||
path, firstlineno = code.path, code.firstlineno
|
path, firstlineno = code.path, code.firstlineno
|
||||||
traceback = excinfo.traceback
|
traceback = excinfo.traceback
|
||||||
ntraceback = traceback.cut(path=path, firstlineno=firstlineno)
|
ntraceback = traceback.cut(path=path, firstlineno=firstlineno)
|
||||||
|
@ -1949,7 +1947,7 @@ def getfuncargnames(function, startindex=None):
|
||||||
if realfunction != function:
|
if realfunction != function:
|
||||||
startindex += num_mock_patch_args(function)
|
startindex += num_mock_patch_args(function)
|
||||||
function = realfunction
|
function = realfunction
|
||||||
if isinstance(function, py.std.functools.partial):
|
if isinstance(function, functools.partial):
|
||||||
argnames = inspect.getargs(py.code.getrawcode(function.func))[0]
|
argnames = inspect.getargs(py.code.getrawcode(function.func))[0]
|
||||||
partial = function
|
partial = function
|
||||||
argnames = argnames[len(partial.args):]
|
argnames = argnames[len(partial.args):]
|
||||||
|
|
Loading…
Reference in New Issue