summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unittest
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-08-24 12:07:20 (GMT)
committerGitHub <noreply@github.com>2022-08-24 12:07:20 (GMT)
commit4de06e3cc0a58d73934f9a2759ad9cd2f6b031b0 (patch)
tree4f571482c2fdab89dcabf9b864364926881e82be /Lib/test/test_unittest
parent420f39f457a97a9379f8423a81776bef428d0746 (diff)
downloadcpython-4de06e3cc0a58d73934f9a2759ad9cd2f6b031b0.zip
cpython-4de06e3cc0a58d73934f9a2759ad9cd2f6b031b0.tar.gz
cpython-4de06e3cc0a58d73934f9a2759ad9cd2f6b031b0.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_unittest')
-rw-r--r--Lib/test/test_unittest/test_async_case.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_unittest/test_async_case.py b/Lib/test/test_unittest/test_async_case.py
index f59fc76..d7d4dc9 100644
--- a/Lib/test/test_unittest/test_async_case.py
+++ b/Lib/test/test_unittest/test_async_case.py
@@ -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: