[issue24651] Mock.assert* API is in user namespace

2015-07-28 Thread Kevin Benton

Kevin Benton added the comment:

I like the idea of having the new module functions without deprecating the old 
ones. Then projects can encourage use of the API on their own terms. Maybe 
there could even be a global that projects could set that would disable the 
object methods...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24651
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24651] Mock.assert* API is in user namespace

2015-07-21 Thread Kevin Benton

Kevin Benton added the comment:

What about other methods/properties like called, call_count, and reset_mock? It 
seems that they should be removed as well to be consistent with the reason for 
this change.

--
nosy: +kevinbenton

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24651
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23078] unittest.mock patch autospec doesn't work on staticmethods

2014-12-18 Thread Kevin Benton

New submission from Kevin Benton:

If one of the mock.patch methods is used with autospec=True on a staticmethod 
in an object, the mock library determines that it is not callable by checking 
for the __call__ attribute. This results in a NonCallableMagicMock being 
returned which of course dies with the following error when the mocked method 
is called:

TypeError: 'NonCallableMagicMock' object is not callable


It seems that the create_autospec needs to special case for classmethod and 
staticmethod.



The following change seems to fix it, however I am only vaguely familiar with 
the internals of mock so I'm not sure what this breaks.

diff -r d356250e275d mock.py
--- a/mock.py   Tue Apr 09 14:53:33 2013 +0100
+++ b/mock.py   Wed Dec 17 07:35:15 2014 -0800
@@ -2191,7 +2191,8 @@
 # descriptors don't have a spec
 # because we don't know what type they return
 _kwargs = {}
-elif not _callable(spec):
+elif not _callable(spec) and not isinstance(spec, (staticmethod,
+   classmethod)):
 Klass = NonCallableMagicMock
 elif is_type and instance and not _instance_callable(spec):
 Klass = NonCallableMagicMock

--
components: Tests
messages: 232864
nosy: kevinbenton, michael.foord
priority: normal
severity: normal
status: open
title: unittest.mock patch autospec doesn't work on staticmethods
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23078
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com