mirror of https://github.com/python/cpython.git
[3.11] GH-95736: fix IsolatedAsyncioTestCase to initialize Runner bef… (#96042)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
1b9b4856c8
commit
b68ea2a3e4
|
@ -79,6 +79,10 @@ async def enterAsyncContext(self, cm):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _callSetUp(self):
|
def _callSetUp(self):
|
||||||
|
# Force loop to be initialized and set as the current loop
|
||||||
|
# so that setUp functions can use get_event_loop() and get the
|
||||||
|
# correct loop instance.
|
||||||
|
self._asyncioRunner.get_loop()
|
||||||
self._asyncioTestContext.run(self.setUp)
|
self._asyncioTestContext.run(self.setUp)
|
||||||
self._callAsync(self.asyncSetUp)
|
self._callAsync(self.asyncSetUp)
|
||||||
|
|
||||||
|
|
|
@ -434,6 +434,21 @@ async def cleanup(self, fut):
|
||||||
test.doCleanups()
|
test.doCleanups()
|
||||||
self.assertEqual(events, ['asyncSetUp', 'test', 'cleanup'])
|
self.assertEqual(events, ['asyncSetUp', 'test', 'cleanup'])
|
||||||
|
|
||||||
|
def test_setup_get_event_loop(self):
|
||||||
|
# See https://github.com/python/cpython/issues/95736
|
||||||
|
# Make sure the default event loop is not used
|
||||||
|
asyncio.set_event_loop(None)
|
||||||
|
|
||||||
|
class TestCase1(unittest.IsolatedAsyncioTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
asyncio.get_event_loop_policy().get_event_loop()
|
||||||
|
|
||||||
|
async def test_demo1(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
test = TestCase1('test_demo1')
|
||||||
|
result = test.run()
|
||||||
|
self.assertTrue(result.wasSuccessful())
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix :class:`unittest.IsolatedAsyncioTestCase` to set event loop before calling setup functions. Patch by Kumar Aditya.
|
Loading…
Reference in New Issue