|
12 | 12 | from unittest.mock import ( |
13 | 13 | NonCallableMock, CallableMixin, patch, sentinel, |
14 | 14 | MagicMock, Mock, NonCallableMagicMock, patch, _patch, |
15 | | - DEFAULT, call, _get_target |
| 15 | + DEFAULT, call, _get_target, _patch |
16 | 16 | ) |
17 | 17 |
|
18 | 18 |
|
@@ -1779,6 +1779,23 @@ def patched(mock_path): |
1779 | 1779 | patched() |
1780 | 1780 | self.assertIs(os.path, path) |
1781 | 1781 |
|
| 1782 | + def test_stopall_lifo(self): |
| 1783 | + stopped = [] |
| 1784 | + class thing(object): |
| 1785 | + one = two = three = None |
| 1786 | + |
| 1787 | + def get_patch(attribute): |
| 1788 | + class mypatch(_patch): |
| 1789 | + def stop(self): |
| 1790 | + stopped.append(attribute) |
| 1791 | + return super(mypatch, self).stop() |
| 1792 | + return mypatch(lambda: thing, attribute, None, None, |
| 1793 | + False, None, None, None, {}) |
| 1794 | + [get_patch(val).start() for val in ("one", "two", "three")] |
| 1795 | + patch.stopall() |
| 1796 | + |
| 1797 | + self.assertEqual(stopped, ["three", "two", "one"]) |
| 1798 | + |
1782 | 1799 |
|
1783 | 1800 | if __name__ == '__main__': |
1784 | 1801 | unittest.main() |
0 commit comments