unittest.mock: a mock created by patch with a spec as the list argument will be callable if __call__ is in the spec

This commit is contained in:
Michael Foord 2012-03-25 19:53:18 +01:00
parent 87b3caf873
commit e58a562d93
2 changed files with 28 additions and 1 deletions

View file

@ -1742,6 +1742,26 @@ class PatchTest(unittest.TestCase):
p.stop()
def test_callable_spec_as_list(self):
spec = ('__call__',)
p = patch(MODNAME, spec=spec)
m = p.start()
try:
self.assertTrue(callable(m))
finally:
p.stop()
def test_not_callable_spec_as_list(self):
spec = ('foo', 'bar')
p = patch(MODNAME, spec=spec)
m = p.start()
try:
self.assertFalse(callable(m))
finally:
p.stop()
if __name__ == '__main__':
unittest.main()