This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Antoni Szych
Recipients Antoni Szych, eric.snow, kakuma, kushal.das, lwcolton, michael.foord
Date 2017-07-12.11:44:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1499859842.87.0.71340441295.issue21600@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

It's been 3 years now since this issue was first raised.
We bumped upon this issue while using code like following:

def tearDown():
    patch.stopall()

def test123():
    p=patch.dict(...)
    p.start()
    assert False
    p.stop()


While `patch.stopall()` is run, it doesn't stop anything. This is because `p.start()` in fact executes `mock._patch_dict._patch_dict()`, which does not execute `self._active_patches.append(self)` (like ordinary `p=patch(...).start()` would).

I could understand that this is just a design choice (which may seem unintuitive for me, but possibly perfectly good for others), however the official documentation [1] states:

>**All** the patchers have start() and stop() methods.

And few lines below [2], we have:

>patch.stopall() Stop all active patches. Only stops patches started with start.

The above is not true for `patch.dict()`, so the documentation is unfortunatelly misleading.


Is there a possibility to fix this in some 3.5 maintenance release (preferably code, not docs :) )?


If anyone else will have the same issue: for now a workaround would be to use `patch.dict()` either as a decorator, or as a context manager (`with patch.dict()`).


[1] https://docs.python.org/3/library/unittest.mock.html#patch-methods-start-and-stop
[2] https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch.stopall
History
Date User Action Args
2017-07-12 11:44:02Antoni Szychsetrecipients: + Antoni Szych, michael.foord, eric.snow, kushal.das, kakuma, lwcolton
2017-07-12 11:44:02Antoni Szychsetmessageid: <1499859842.87.0.71340441295.issue21600@psf.upfronthosting.co.za>
2017-07-12 11:44:02Antoni Szychlinkissue21600 messages
2017-07-12 11:44:02Antoni Szychcreate