[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2018-12-12 Thread Chris Withers


Change by Chris Withers :


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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2018-12-12 Thread miss-islington


Change by miss-islington :


--
pull_requests: +10358

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2018-12-10 Thread Chris Withers


Chris Withers  added the comment:

Ah, yeah, I can see the blanket patch and a more local patch in a monorepo 
being a thing, cool, let's have a look!

--

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2018-12-10 Thread Anthony Sottile


Anthony Sottile  added the comment:

to be honest, I don't recall exactly given it's been 2 and a half years since 
the original report with no activity.

if I recall correctly, this was encountered while upgrading the `mock` backport 
in yelp's monolithic repository.

I want to say the reason this was hard to "fix" properly was due to some 
blanket patches being applied in a base test case and then other test cases 
re-patching those methods to add more specific behaviour.  This worked fine in 
python2.7 and all the way until python3.3 but then was broken by changes in 
python3.4

Fortunately, they've been fixed in python3.7.  I guess I've been encouraged to 
write a patch with a test so it does not regress in the future

--

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2018-12-10 Thread Chris Withers


Chris Withers  added the comment:

Before we get too far: what's the use case for this double patching?

--

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2018-12-10 Thread Anthony Sottile


Anthony Sottile  added the comment:

I've opened a PR with the test included: 
https://github.com/python/cpython/pull/11085

--

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2018-12-10 Thread Anthony Sottile


Change by Anthony Sottile :


--
pull_requests: +10317

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2018-12-09 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Thanks @asottile for the patch. I think the original AttributeError is resolved 
with issue28919 where they were silenced. It seems similar to issue32153 though 
the exception occurs from mock instead of partial object as in issue32153. The 
fix was applied to 3.7+ and hence 3.6 was not fixed which enters security fix 
only mode shortly. The attached tests also pass on master and I think it will 
it be a good unittest addition to Lib/unittest/test/testmock/testwith.py 
(similar to issue32153) that has a couple of nested with statements for the 
same attribute. Adding cjw296 to the list.

--
nosy: +cjw296, xtreak

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2016-05-01 Thread Anthony Sottile

Anthony Sottile added the comment:

Seems I've named the patchfile incorrectly -- Hopefully this is correct this 
time?

--
keywords: +patch
nosy: +Anthony Sottile
Added file: http://bugs.python.org/file42675/2.patch

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2016-04-07 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +michael.foord
stage:  -> patch review
type: crash -> behavior
versions:  -Python 3.4

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2016-04-06 Thread Anthony Sottile

Anthony Sottile added the comment:

Here's an improved patch which:

- passes the tests
- puts the test in the correct place

I'm not entirely happy with the approach -- open to suggestions :)

--
Added file: http://bugs.python.org/file42387/patch2

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2016-04-06 Thread Anthony Sottile

Anthony Sottile added the comment:

The root cause seems to be that autospecced functions return a function object 
(not a Mock instance) which a '.mock' attribute which is a MagicMock ( assigned 
here: 
https://github.com/python/cpython/blob/ae775ab1eb72f42de2d070158bade4bf261ac04f/Lib/unittest/mock.py#L198
 )

I took a first stab at a patch (attached)

--
Added file: http://bugs.python.org/file42384/patch

___
Python tracker 

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



[issue26704] unittest.mock.patch: Double patching instance method: AttributeError: Mock object has no attribute '__name__'

2016-04-06 Thread Anthony Sottile

New submission from Anthony Sottile:

Originally from https://github.com/testing-cabal/mock/issues/350

## Example
```python
from unittest import mock

class C(object):
def f(self):
pass

c = C()

with mock.patch.object(c, 'f', autospec=True):
with mock.patch.object(c, 'f', autospec=True):
pass
```

## Python3.3

```
$ test.py
$
```

## Python3.4 / 3.5 / 3.6 (From gitbhub.com/python/cpython@fa3fc6d7)

```
Traceback (most recent call last):
  File "test.py", line 10, in 
with mock.patch.object(c, 'f', autospec=True):
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 1320, in 
__enter__
_name=self.attribute, **kwargs)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 2220, in 
create_autospec
_check_signature(original, new, skipfirst=skipfirst)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 112, in 
_check_signature
_copy_func_details(func, checksig)
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 117, in 
_copy_func_details
funcopy.__name__ = func.__name__
  File "/home/asottile/workspace/cpython/Lib/unittest/mock.py", line 578, in 
__getattr__
raise AttributeError("Mock object has no attribute %r" % name)
AttributeError: Mock object has no attribute '__name__'
```

--
components: Library (Lib)
messages: 262960
nosy: asottile
priority: normal
severity: normal
status: open
title: unittest.mock.patch: Double patching instance method: AttributeError: 
Mock object has no attribute '__name__'
type: crash
versions: Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

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