New submission from Lisa Roach <lisaroac...@gmail.com>:
Hard to explain in the title, easier to see via a test case: async def async_func(): raise Exception def test_simultaneous_mocks(self): class Test(IsolatedAsyncioTestCase): async def test_test(self): patcher1 = patch(f"{__name__}.async_func") patcher2 = patch(f"{__name__}.async_func") patcher1.start() await async_func() patcher2.start() await async_func() patcher1.stop() with self.assertRaises(Exception): await async_func() patcher2.stop() with self.assertRaises(Exception): # Fails, mock is restored! await async_func() test = Test("test_test") output = test.run() self.assertTrue(output.wasSuccessful()) # Fail Calling stop() on the second patch actually restores the mock and causes the test to fail. ---------- assignee: lisroach messages: 379687 nosy: lisroach priority: normal severity: normal status: open title: AsyncMock restores stopped patch if same object stopped multiple times versions: Python 3.10, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42159> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com