Skip to content
Snippets Groups Projects
Unverified Commit 9b070d36 authored by Miss Islington (bot)'s avatar Miss Islington (bot) Committed by GitHub
Browse files

gh-96021: Explicitly tear down the IsolatedAsyncioTestCase loop in tests (GH-96135) (GH-96235)


Tests for IsolatedAsyncioTestCase.debug() rely on the runner be closed
in __del__. It makes tests depending on the GC an unreliable on other
implementations. It is better to tear down the loop explicitly even if
currently there is no a public API for this.
(cherry picked from commit 4de06e3c)

Co-authored-by: default avatarSerhiy Storchaka <storchaka@gmail.com>
parent c0a9859a
No related branches found
No related tags found
No related merge requests found
...@@ -14,10 +14,10 @@ def tearDownModule(): ...@@ -14,10 +14,10 @@ def tearDownModule():
class TestAsyncCase(unittest.TestCase): class TestAsyncCase(unittest.TestCase):
maxDiff = None maxDiff = None
def tearDown(self): def setUp(self):
# Ensure that IsolatedAsyncioTestCase instances are destroyed before # Ensure that IsolatedAsyncioTestCase instances are destroyed before
# starting a new event loop # starting a new event loop
support.gc_collect() self.addCleanup(support.gc_collect)
def test_full_cycle(self): def test_full_cycle(self):
class Test(unittest.IsolatedAsyncioTestCase): class Test(unittest.IsolatedAsyncioTestCase):
...@@ -108,6 +108,7 @@ async def on_cleanup(self): ...@@ -108,6 +108,7 @@ async def on_cleanup(self):
events = [] events = []
test = Test("test_func") test = Test("test_func")
self.addCleanup(test._tearDownAsyncioLoop)
try: try:
test.debug() test.debug()
except MyException: except MyException:
...@@ -143,6 +144,7 @@ async def on_cleanup(self): ...@@ -143,6 +144,7 @@ async def on_cleanup(self):
events = [] events = []
test = Test("test_func") test = Test("test_func")
self.addCleanup(test._tearDownAsyncioLoop)
try: try:
test.debug() test.debug()
except MyException: except MyException:
...@@ -178,6 +180,7 @@ async def on_cleanup(self): ...@@ -178,6 +180,7 @@ async def on_cleanup(self):
events = [] events = []
test = Test("test_func") test = Test("test_func")
self.addCleanup(test._tearDownAsyncioLoop)
try: try:
test.debug() test.debug()
except MyException: except MyException:
...@@ -219,6 +222,7 @@ async def on_cleanup2(self): ...@@ -219,6 +222,7 @@ async def on_cleanup2(self):
events = [] events = []
test = Test("test_func") test = Test("test_func")
self.addCleanup(test._tearDownAsyncioLoop)
try: try:
test.debug() test.debug()
except MyException: except MyException:
...@@ -331,6 +335,7 @@ async def cleanup(self, fut): ...@@ -331,6 +335,7 @@ async def cleanup(self, fut):
events = [] events = []
test = Test("test_func") test = Test("test_func")
self.addCleanup(test._tearDownAsyncioLoop)
try: try:
test.debug() test.debug()
except MyException: except MyException:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment