8000 gh-96030: IsolatedAsyncioTestCase: don't create asyncio runner for sk… · tiran/cpython@c56793a · GitHub
[go: up one dir, main page]

Skip to content

Commit c56793a

Browse files
committed
pythongh-96030: IsolatedAsyncioTestCase: don't create asyncio runner for skipped tests
1 parent f215d7c commit c56793a

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

Lib/unittest/async_case.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,26 @@ async def enterAsyncContext(self, cm):
7979
return result
8080

8181
def _callSetUp(self):
82-
self._asyncioTestContext.run(self.setUp)
83-
self._callAsync(self.asyncSetUp)
82+
self._setupAsyncioRunner()
83+
try:
84+
self._asyncioTestContext.run(self.setUp)
85+
self._callAsync(self.asyncSetUp)
86+
except Exception:
87+
# _callTearDown is not called when _callSetUp fails.
88+
self._tearDownAsyncioRunner()
89+
raise
8490

8591
def _callTestMethod(self, method):
8692
if self._callMaybeAsync(method) is not None:
8793
warnings.warn(f'It is deprecated to return a value!=None from a '
8894
f'test case ({method})', DeprecationWarning, stacklevel=4)
8995

9096
def _callTearDown(self):
91-
self._callAsync(self.asyncTearDown)
92-
self._asyncioTestContext.run(self.tearDown)
97+
try:
98+
self._callAsync(self.asyncTearDown)
99+
self._asyncioTestContext.run(self.tearDown)
100+
finally:
101+
self._tearDownAsyncioRunner()
93102

94103
def _callCleanup(self, function, *args, **kwargs):
95104
self._callMaybeAsync(function, *args, **kwargs)
@@ -125,18 +134,6 @@ def _tearDownAsyncioRunner(self):
125134
runner = self._asyncioRunner
126135
runner.close()
127136

128-
def run(self, result=None):
129-
self._setupAsyncioRunner()
130-
try:
131-
return super().run(result)
132-
finally:
133-
self._tearDownAsyncioRunner()
134-
135-
def debug(self):
136-
self._setupAsyncioRunner()
137-
super().debug()
138-
self._tearDownAsyncioRunner()
139-
140137
def __del__(self):
141138
if self._asyncioRunner is not None:
142139
self._tearDownAsyncioRunner()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``run`` method of the internal test helper ``IsolatedAsyncioTestCase``
2+
no longer sets up an asyncio runner if a test case or class is skipped.

0 commit comments

Comments
 (0)
0