derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Patch not restored when the same attribute is patched twice #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When an attribute is patched twice on the same block (with @patch or with),
the patch is not completely restored at the end of the block.

Example:

@patch_object('test.something', a_mock)
@patch_object('test.something', a_mock)
def example

Original issue reported on code.google.com by bouf10@gmail.com on 3 Jan 2010 at 9:52

GoogleCodeExporter commented 9 years ago
Tests to reproduce the issue.

Original comment by bouf10@gmail.com on 3 Jan 2010 at 9:54

Attachments:

GoogleCodeExporter commented 9 years ago
What is the usecase for patching the same attribute twice? 

Original comment by fuzzyman on 3 Jan 2010 at 10:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I think you're right about the 'onion peel'. I'll see if I can make it work 
when used
as a context manager as well.

Original comment by fuzzyman on 3 Jan 2010 at 11:10

GoogleCodeExporter commented 9 years ago
No real use case except when the developer do it by error. The problem is that 
it
seems to create a strange side effect where other methods decorated executed 
after
starts to fail.

So I thought that it can hide a more deeper bug. And since other tests begin to 
fail,
it took me some time to identified that the real problem was not the failed 
test but
the other one that has a double patch...

Anyway, there is a patch to solve the problem with a decorator (@patch) but not 
for
the with statement. 

The problem was in the execution order of the __exit__ method. I think that it 
should
be executed in the reverse order from __enter__ (like an onion peel).

(Sorry I'm not used to GoogleCode, I had to repost this comment)

Original comment by bouf10@gmail.com on 3 Jan 2010 at 11:16

Attachments:

GoogleCodeExporter commented 9 years ago
Finally, it shows up that the remaining bug with the with statement was in the 
test
itself... 

So this is my patch to fix the issue 21 (the test is included to prevent 
regression).
Patch is against SVN r99.

Original comment by bouf10@gmail.com on 4 Jan 2010 at 1:32

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 11 Jun 2010 at 12:02

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 12 Jun 2010 at 11:23

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 13 Jun 2010 at 8:41

GoogleCodeExporter commented 9 years ago

Original comment by kon...@gmail.com on 13 Jun 2010 at 9:31