mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
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 4de06e3cc0)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
c0a9859afb
commit
9b070d361d
1 changed files with 7 additions and 2 deletions
|
|
@ -14,10 +14,10 @@ def tearDownModule():
|
|||
class TestAsyncCase(unittest.TestCase):
|
||||
maxDiff = None
|
||||
|
||||
def tearDown(self):
|
||||
def setUp(self):
|
||||
# Ensure that IsolatedAsyncioTestCase instances are destroyed before
|
||||
# starting a new event loop
|
||||
support.gc_collect()
|
||||
self.addCleanup(support.gc_collect)
|
||||
|
||||
def test_full_cycle(self):
|
||||
class Test(unittest.IsolatedAsyncioTestCase):
|
||||
|
|
@ -108,6 +108,7 @@ async def on_cleanup(self):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioLoop)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
|
@ -143,6 +144,7 @@ async def on_cleanup(self):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioLoop)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
|
@ -178,6 +180,7 @@ async def on_cleanup(self):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioLoop)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
|
@ -219,6 +222,7 @@ async def on_cleanup2(self):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioLoop)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
|
@ -331,6 +335,7 @@ async def cleanup(self, fut):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioLoop)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue