fix issue473: work around mock putting an unbound method into a class

dict when double-patching.

--HG--
branch : issue473
This commit is contained in:
holger krekel 2014-04-08 12:50:13 +02:00
parent ef7cb47b1e
commit f91049cec9
3 changed files with 20 additions and 0 deletions

View File

@ -1,6 +1,9 @@
NEXT (2.6)
-----------------------------------
- fix issue473: work around mock putting an unbound method into a class
dict when double-patching.
- fix issue498: if a fixture finalizer fails, make sure that
the fixture is still invalidated.

View File

@ -222,6 +222,8 @@ def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
return Class(name, parent=collector)
elif collector.funcnamefilter(name) and hasattr(obj, "__call__") and \
getfixturemarker(obj) is None:
# mock seems to store unbound methods (issue473), let's normalize it
obj = getattr(obj, "__func__", obj)
if not isfunction(obj):
collector.warn(code="C2", message=
"cannot collect %r because it is not a function."

View File

@ -164,6 +164,21 @@ class TestMockDecoration:
names = [x.nodeid.split("::")[-1] for x in calls]
assert names == ["test_one", "test_two", "test_three"]
def test_mock_double_patch_issue473(self, testdir):
testdir.makepyfile("""
from mock import patch
from pytest import mark
@patch('os.getcwd')
@patch('os.path')
@mark.slow
class TestSimple:
def test_simple_thing(self, mock_path, mock_getcwd):
pass
""")
res = testdir.inline_run()
res.assertoutcome(passed=1)
class TestReRunTests:
def test_rerun(self, testdir):