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

2019-04-21 Thread Berker Peksag


Berker Peksag  added the comment:

Thank you!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
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

2019-04-21 Thread Berker Peksag


Berker Peksag  added the comment:


New changeset 15a57a3cadb992bb1752302333ff593e7eab284c by Berker Peksag in 
branch '3.7':
bpo-23078: Add support for {class,static}method to mock.create_autospec() 
(GH-11613)
https://github.com/python/cpython/commit/15a57a3cadb992bb1752302333ff593e7eab284c


--

___
Python tracker 

___
___
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

2019-04-21 Thread Berker Peksag


Change by Berker Peksag :


--
pull_requests: +12829

___
Python tracker 

___
___
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

2019-04-21 Thread Berker Peksag


Change by Berker Peksag :


--
pull_requests:  -11349

___
Python tracker 

___
___
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

2019-04-21 Thread Berker Peksag


Berker Peksag  added the comment:


New changeset 9b21856b0fcda949de239edc7aa6cf3f2f4f77a3 by Berker Peksag 
(Xtreak) in branch 'master':
bpo-23078:  Add support for {class,static}method to mock.create_autospec() 
(GH-11613)
https://github.com/python/cpython/commit/9b21856b0fcda949de239edc7aa6cf3f2f4f77a3


--

___
Python tracker 

___
___
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

2019-01-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
pull_requests: +11348, 11349, 11350

___
Python tracker 

___
___
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

2019-01-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
pull_requests: +11348, 11349

___
Python tracker 

___
___
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

2019-01-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
pull_requests: +11348

___
Python tracker 

___
___
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

2019-01-17 Thread Felipe


Felipe  added the comment:

Please go ahead with the PR. I can't push this one through, but would be
great to have this finally land!

On Thu, 17 Jan 2019 at 03:42, Karthikeyan Singaravelan <
rep...@bugs.python.org> wrote:

>
> Karthikeyan Singaravelan  added the comment:
>
> @berker.peksag I have converted the patch at
> https://bugs.python.org/file40470/issue23078.patch and pushed it to a
> GitHub branch
> https://github.com/python/cpython/compare/master...tirkarthi:bpo23078 . I
> am willing to open a PR attributing to @fov in case you haven't had the
> time to look into this.
>
> I am removing 3.6 since it's security fixes only mode.
>
> Thanks
>
> --
> nosy: +cjw296, mariocj89, xtreak
> versions:  -Python 3.6
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
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

2019-01-17 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

@berker.peksag I have converted the patch at 
https://bugs.python.org/file40470/issue23078.patch and pushed it to a GitHub 
branch https://github.com/python/cpython/compare/master...tirkarthi:bpo23078 . 
I am willing to open a PR attributing to @fov in case you haven't had the time 
to look into this. 

I am removing 3.6 since it's security fixes only mode.

Thanks

--
nosy: +cjw296, mariocj89, xtreak
versions:  -Python 3.6

___
Python tracker 

___
___
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

2019-01-15 Thread John Parejko


John Parejko  added the comment:

Were you able to make any progress on this? Do you need any help?

--
nosy: +parejkoj-3

___
Python tracker 

___
___
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

2018-12-09 Thread Andrew Tennikoff


Change by Andrew Tennikoff :


--
nosy: +atenni

___
Python tracker 

___
___
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

2018-11-27 Thread Berker Peksag


Berker Peksag  added the comment:

Thanks for the pings. I will work on this issue this weekend. Note that 3.4 and 
3.5 are in security-fix-only mode now, so I removed them from the versions 
field.

--
assignee:  -> berker.peksag
versions:  -Python 3.4, Python 3.5

___
Python tracker 

___
___
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

2018-11-27 Thread John Parejko


John Parejko  added the comment:

Adding to the list of "I just ran into this". The patch submitted by fov seems 
straightforward enough: what can we do to help shepherd it along?

--
nosy: +John Parejko2

___
Python tracker 

___
___
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

2018-11-26 Thread Tom Dalton

Tom Dalton  added the comment:

Here's a minimal example so my comment is not totally vacuous:

```
import unittest
from unittest import mock

class Foo:
@classmethod
def bar(cls, baz):
pass

class TestFoo(unittest.TestCase):
def test_bar(self):
with unittest.mock.patch.object(Foo, "bar", autospec=True):
Foo.bar()
```

->

```
~/› python -m unittest example.py 
E
==
ERROR: test_bar (example.TestFoo)
--
Traceback (most recent call last):
  File "example.py", line 14, in test_bar
Foo.bar()
TypeError: 'NonCallableMagicMock' object is not callable

--
Ran 1 test in 0.001s
```

--

___
Python tracker 

___
___
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

2018-11-26 Thread Tom Dalton


Tom Dalton  added the comment:

I've just come across this too, so would be great if the patch can be 
progressed.

--
nosy: +tom.dalton.fanduel

___
Python tracker 

___
___
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

2018-08-01 Thread Kamil Gałuszka

Kamil Gałuszka  added the comment:

This affects all versions from 3.4 up to 3.8-dev. Would be nice if someone 
could do the review of the supplied patch. 

Thanks for awesome work on Python!

I'm here because it just hit me also and I was for 1 h thinking that I don't 
know how to use patch/mock. ;)

--
nosy: +galuszkak
versions: +Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
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

2018-01-25 Thread Dean Liao

Dean Liao  added the comment:

I planned to upgrade Chromium OS's mock module to 2.0.0. I also encountered the 
issue that classmethod cannot be patched as callable mock.

Reviewers, can we start the review process?

--
nosy: +deanliao

___
Python tracker 

___
___
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

2017-11-08 Thread Germano

Germano  added the comment:

Hi,

I hit this problem wile mocking one static method and found this fix.
Tested it and works for me.
However, I did not find it pushed anywhere: no Python 3.x and no mock for 2.7.

Is there any reason why it is not pushed anywhere, yet?

--
nosy: +germanop

___
Python tracker 

___
___
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

2016-02-10 Thread Erik Purins

Changes by Erik Purins :


--
nosy: +epu

___
Python tracker 

___
___
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

2015-09-14 Thread Felipe

Felipe added the comment:

The attached patch implements these changes through _callable instead. This 
patch also ensures that the underlying object that staticmethod and classmethod 
wrap is a callable object as well.

--
Added file: http://bugs.python.org/file40470/issue23078.patch

___
Python tracker 

___
___
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

2015-06-02 Thread Felipe

Felipe added the comment:

Regarding Claudiu's comment about `staticmethod(x)` or `classmethod(x)` not 
being callable, would it suffice to add a specific check of the form 
`(isinstance(x, (classmethod, staticmethod)) and _callable(x.__func__))`?

Separately, would it be better to include the check for `staticmethod` and 
`classmethod` objects (with an underlying callable) inside the `_callable` 
function? Not sure if this would break anything, but it seems like conceptually 
the issue is with the definition of a callable object, not the selection of 
mock type to use.

--
nosy: +fov

___
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



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

2015-04-14 Thread Kasia Jachim

Changes by Kasia Jachim katarzyna.jac...@gmail.com:


--
nosy: +lukasz.langa

___
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



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

2015-01-22 Thread Claudiu Popa

Claudiu Popa added the comment:

Here's a patch which does this. One problem could be that 
staticmethod(some_callable) or classmethod(some_callable) aren't callable per 
se, but given the fact that users expects Foo.staticmethod or Foo.klassmethod 
to be callable when patching them, it's something we should consider for fixing.

--
components: +Library (Lib) -Tests
keywords: +patch
nosy: +Claudiu.Popa
stage:  - patch review
Added file: http://bugs.python.org/file37818/issue23078.patch

___
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



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

2015-01-22 Thread Berker Peksag

Berker Peksag added the comment:

Looks like b6ea3dc89a78 is not a valid changeset. Could you attach a patch from 
the Mercurial repo?

--
nosy: +berker.peksag
versions:  -Python 2.7

___
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



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

2015-01-22 Thread Claudiu Popa

Changes by Claudiu Popa pcmantic...@gmail.com:


Added file: http://bugs.python.org/file37823/issue23078.patch

___
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



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

2015-01-22 Thread Claudiu Popa

Claudiu Popa added the comment:

Ups, sorry about that, I'll update the patch.

--

___
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



[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