Skip to content

Commit

Permalink
pythongh-96030: IsolatedAsyncioTestCase: don't create asyncio runner …
Browse files Browse the repository at this point in the history
…for skipped tests
  • Loading branch information
tiran committed Aug 16, 2022
1 parent f215d7c commit c31d0e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 13 additions & 16 deletions Lib/unittest/async_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,26 @@ async def enterAsyncContext(self, cm):
return result

def _callSetUp(self):
self._asyncioTestContext.run(self.setUp)
self._callAsync(self.asyncSetUp)
self._setupAsyncioRunner()
try:
self._asyncioTestContext.run(self.setUp)
self._callAsync(self.asyncSetUp)
except Exception:
# _callTearDown is not called when _callSetUp fails.
self._tearDownAsyncioRunner()
raise

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

def _callTearDown(self):
self._callAsync(self.asyncTearDown)
self._asyncioTestContext.run(self.tearDown)
try:
self._callAsync(self.asyncTearDown)
self._asyncioTestContext.run(self.tearDown)
finally:
self._tearDownAsyncioRunner()

def _callCleanup(self, function, *args, **kwargs):
self._callMaybeAsync(function, *args, **kwargs)
Expand Down Expand Up @@ -125,18 +134,6 @@ def _tearDownAsyncioRunner(self):
runner = self._asyncioRunner
runner.close()

def run(self, result=None):
self._setupAsyncioRunner()
try:
return super().run(result)
finally:
self._tearDownAsyncioRunner()

def debug(self):
self._setupAsyncioRunner()
super().debug()
self._tearDownAsyncioRunner()

def __del__(self):
if self._asyncioRunner is not None:
self._tearDownAsyncioRunner()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The ``run`` method of :class:`unittest.IsolatedAsyncioTestCase`
no longer sets up an asyncio runner if a test case or class is skipped.

0 comments on commit c31d0e8

Please sign in to comment.