mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-96021: Explicitly close the IsolatedAsyncioTestCase runner in tests (GH-96135)
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 close the runner explicitly even if currently there is no a public API for this.
This commit is contained in:
parent
420f39f457
commit
4de06e3cc0
1 changed files with 7 additions and 2 deletions
|
@ -43,10 +43,10 @@ VAR = contextvars.ContextVar('VAR', default=())
|
|||
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):
|
||||
|
@ -151,6 +151,7 @@ class TestAsyncCase(unittest.TestCase):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioRunner)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
@ -186,6 +187,7 @@ class TestAsyncCase(unittest.TestCase):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioRunner)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
@ -221,6 +223,7 @@ class TestAsyncCase(unittest.TestCase):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioRunner)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
@ -262,6 +265,7 @@ class TestAsyncCase(unittest.TestCase):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioRunner)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
@ -424,6 +428,7 @@ class TestAsyncCase(unittest.TestCase):
|
|||
|
||||
events = []
|
||||
test = Test("test_func")
|
||||
self.addCleanup(test._tearDownAsyncioRunner)
|
||||
try:
|
||||
test.debug()
|
||||
except MyException:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue