|
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 |
|
@@ -1799,6 +1799,23 @@ def patched(mock_path): |
1799 | 1799 | patched() |
1800 | 1800 | self.assertIs(os.path, path) |
1801 | 1801 |
|
| 1802 | + def test_stopall_lifo(self): |
| 1803 | + stopped = [] |
| 1804 | + class thing(object): |
| 1805 | + one = two = three = None |
| 1806 | + |
| 1807 | + def get_patch(attribute): |
| 1808 | + class mypatch(_patch): |
| 1809 | + def stop(self): |
| 1810 | + stopped.append(attribute) |
| 1811 | + return super(mypatch, self).stop() |
| 1812 | + return mypatch(lambda: thing, attribute, None, None, |
| 1813 | + False, None, None, None, {}) |
| 1814 | + [get_patch(val).start() for val in ("one", "two", "three")] |
| 1815 | + patch.stopall() |
| 1816 | + |
| 1817 | + self.assertEqual(stopped, ["three", "two", "one"]) |
| 1818 | + |
1802 | 1819 |
|
1803 | 1820 | if __name__ == '__main__': |
1804 | 1821 | unittest.main() |
0 commit comments