diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-03-25 19:53:18 +0100 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-03-25 19:53:18 +0100 |
commit | e58a562d9395b8a4ed9419b735cad9f78c8ae802 (patch) | |
tree | 120e3cd3e4a8d791a17669c96d28068fcf9bce8c /Lib/unittest/mock.py | |
parent | 87b3caf873a45fd836982296374f5b4e49dd9e30 (diff) | |
download | cpython-git-e58a562d9395b8a4ed9419b735cad9f78c8ae802.tar.gz |
unittest.mock: a mock created by patch with a spec as the list argument will be callable if __call__ is in the spec
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index d73bd5385f..4809dba594 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1166,7 +1166,14 @@ class _patch(object): if new_callable is not None: Klass = new_callable elif spec is not None or spec_set is not None: - if not _callable(spec or spec_set): + this_spec = spec + if spec_set is not None: + this_spec = spec_set + if _is_list(this_spec): + not_callable = '__call__' not in this_spec + else: + not_callable = not callable(this_spec) + if not_callable: Klass = NonCallableMagicMock if spec is not None: |