diff options
author | Michael Foord <michael@voidspace.org.uk> | 2014-04-15 21:21:08 (GMT) |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2014-04-15 21:21:08 (GMT) |
commit | ebc1a30d55f07d590d62504c3f097cb8a15ee7d3 (patch) | |
tree | 85c1d4b0d2efdced930ac423a207c29e569476ce /Lib/unittest/test/testmock/testpatch.py | |
parent | d943fdee87a1f3a6e2b855369c7b343d50da49ed (diff) | |
download | cpython-ebc1a30d55f07d590d62504c3f097cb8a15ee7d3.zip cpython-ebc1a30d55f07d590d62504c3f097cb8a15ee7d3.tar.gz cpython-ebc1a30d55f07d590d62504c3f097cb8a15ee7d3.tar.bz2 |
Closes issue 21239. unittest.mock.patch.stopall() did not work deterministically when the same name was patched multiple times.
Diffstat (limited to 'Lib/unittest/test/testmock/testpatch.py')
-rw-r--r-- | Lib/unittest/test/testmock/testpatch.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py index c1bc34f..b516f42 100644 --- a/Lib/unittest/test/testmock/testpatch.py +++ b/Lib/unittest/test/testmock/testpatch.py @@ -12,7 +12,7 @@ from unittest.test.testmock.support import SomeClass, is_instance from unittest.mock import ( NonCallableMock, CallableMixin, patch, sentinel, MagicMock, Mock, NonCallableMagicMock, patch, _patch, - DEFAULT, call, _get_target + DEFAULT, call, _get_target, _patch ) @@ -1779,6 +1779,23 @@ class PatchTest(unittest.TestCase): patched() self.assertIs(os.path, path) + def test_stopall_lifo(self): + stopped = [] + class thing(object): + one = two = three = None + + def get_patch(attribute): + class mypatch(_patch): + def stop(self): + stopped.append(attribute) + return super(mypatch, self).stop() + return mypatch(lambda: thing, attribute, None, None, + False, None, None, None, {}) + [get_patch(val).start() for val in ("one", "two", "three")] + patch.stopall() + + self.assertEqual(stopped, ["three", "two", "one"]) + if __name__ == '__main__': unittest.main() |