Message379687
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. |
|
Date |
User |
Action |
Args |
2020-10-26 21:05:24 | lisroach | set | recipients:
+ lisroach |
2020-10-26 21:05:24 | lisroach | set | messageid: <1603746324.52.0.94475530038.issue42159@roundup.psfhosted.org> |
2020-10-26 21:05:24 | lisroach | link | issue42159 messages |
2020-10-26 21:05:24 | lisroach | create | |
|