summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-08-28 05:35:39 (GMT)
committerGitHub <noreply@github.com>2022-08-28 05:35:39 (GMT)
commit9b070d361da2d1458ba005e2451b26d698c1fbf7 (patch)
tree4d6b7a31138512533fe4ccb8b06679dc53c3f96e /Lib/unittest
parentc0a9859afb522d555a9b9851be48be56327d252d (diff)
downloadcpython-9b070d361da2d1458ba005e2451b26d698c1fbf7.zip
cpython-9b070d361da2d1458ba005e2451b26d698c1fbf7.tar.gz
cpython-9b070d361da2d1458ba005e2451b26d698c1fbf7.tar.bz2
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 4de06e3cc0a58d73934f9a2759ad9cd2f6b031b0) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/test/test_async_case.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/unittest/test/test_async_case.py b/Lib/unittest/test/test_async_case.py
index e46b99f..b97ad93 100644
--- a/Lib/unittest/test/test_async_case.py
+++ b/Lib/unittest/test/test_async_case.py
@@ -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 @@ class TestAsyncCase(unittest.TestCase):
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException:
@@ -143,6 +144,7 @@ class TestAsyncCase(unittest.TestCase):
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException:
@@ -178,6 +180,7 @@ class TestAsyncCase(unittest.TestCase):
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException:
@@ -219,6 +222,7 @@ class TestAsyncCase(unittest.TestCase):
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException:
@@ -331,6 +335,7 @@ class TestAsyncCase(unittest.TestCase):
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException: