Fix to work properly when @patch is used with new not equal to DEFAULT
also updated test_mock to include this situation
This commit is contained in:
parent
2893cddb68
commit
3388d82c1c
|
@ -1836,6 +1836,12 @@ def getfuncargnames(function, startindex=None):
|
||||||
if startindex is None:
|
if startindex is None:
|
||||||
startindex = inspect.ismethod(function) and 1 or 0
|
startindex = inspect.ismethod(function) and 1 or 0
|
||||||
if realfunction != function:
|
if realfunction != function:
|
||||||
|
try:
|
||||||
|
from mock import DEFAULT
|
||||||
|
for patching in getattr(function, "patchings", []):
|
||||||
|
if not patching.attribute_name and patching.new is DEFAULT:
|
||||||
|
startindex += 1
|
||||||
|
except ImportError:
|
||||||
startindex += len(getattr(function, "patchings", []))
|
startindex += len(getattr(function, "patchings", []))
|
||||||
function = realfunction
|
function = realfunction
|
||||||
argnames = inspect.getargs(py.code.getrawcode(function))[0]
|
argnames = inspect.getargs(py.code.getrawcode(function))[0]
|
||||||
|
|
|
@ -124,8 +124,11 @@ class TestMockDecoration:
|
||||||
def test_hello(self, abspath):
|
def test_hello(self, abspath):
|
||||||
os.path.abspath("hello")
|
os.path.abspath("hello")
|
||||||
abspath.assert_any_call("hello")
|
abspath.assert_any_call("hello")
|
||||||
|
def mock_basename(path):
|
||||||
|
return "mock_basename"
|
||||||
@mock.patch("os.path.abspath")
|
@mock.patch("os.path.abspath")
|
||||||
@mock.patch("os.path.normpath")
|
@mock.patch("os.path.normpath")
|
||||||
|
@mock.patch("os.path.basename",new=mock_basename)
|
||||||
def test_someting(normpath, abspath, tmpdir):
|
def test_someting(normpath, abspath, tmpdir):
|
||||||
abspath.return_value = "this"
|
abspath.return_value = "this"
|
||||||
os.path.normpath(os.path.abspath("hello"))
|
os.path.normpath(os.path.abspath("hello"))
|
||||||
|
|
Loading…
Reference in New Issue