Antoni Szych added the comment:
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
----------
nosy: +Antoni Szych
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue21600>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com