This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lisroach
Recipients lisroach
Date 2020-10-26.21:05:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1603746324.52.0.94475530038.issue42159@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-10-26 21:05:24lisroachsetrecipients: + lisroach
2020-10-26 21:05:24lisroachsetmessageid: <1603746324.52.0.94475530038.issue42159@roundup.psfhosted.org>
2020-10-26 21:05:24lisroachlinkissue42159 messages
2020-10-26 21:05:24lisroachcreate