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>
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):
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException:
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException:
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException:
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException:
events = []
test = Test("test_func")
+ self.addCleanup(test._tearDownAsyncioLoop)
try:
test.debug()
except MyException: