Add unittest features new in Python 3.11 (#8020)

python/cpython@086c6b1
This commit is contained in:
Alex Waygood
2022-06-04 16:27:52 +01:00
committed by GitHub
parent e30ff13b7d
commit 0ce825b5a8
4 changed files with 21 additions and 10 deletions

View File

@@ -33,7 +33,7 @@ if sys.version_info >= (3, 8):
from .case import addModuleCleanup as addModuleCleanup
if sys.version_info >= (3, 11):
from .case import doModuleCleanups as doModuleCleanups
from .case import doModuleCleanups as doModuleCleanups, enterModuleContext as enterModuleContext
if sys.version_info >= (3, 11):
__all__ = [
@@ -58,6 +58,7 @@ if sys.version_info >= (3, 11):
"removeHandler",
"addModuleCleanup",
"doModuleCleanups",
"enterModuleContext",
"getTestCaseNames",
"makeSuite",
"findTestCases",

View File

@@ -1,11 +1,19 @@
import sys
from collections.abc import Awaitable, Callable
from typing import TypeVar
from typing_extensions import ParamSpec
from .case import TestCase
if sys.version_info >= (3, 11):
from contextlib import AbstractAsyncContextManager
_T = TypeVar("_T")
_P = ParamSpec("_P")
class IsolatedAsyncioTestCase(TestCase):
async def asyncSetUp(self) -> None: ...
async def asyncTearDown(self) -> None: ...
def addAsyncCleanup(self, __func: Callable[_P, Awaitable[object]], *args: _P.args, **kwargs: _P.kwargs) -> None: ...
if sys.version_info >= (3, 11):
async def enterAsyncContext(self, cm: AbstractAsyncContextManager[_T]) -> _T: ...

View File

@@ -13,6 +13,7 @@ from warnings import WarningMessage
if sys.version_info >= (3, 9):
from types import GenericAlias
_T = TypeVar("_T")
_E = TypeVar("_E", bound=BaseException)
_FT = TypeVar("_FT", bound=Callable[..., Any])
_P = ParamSpec("_P")
@@ -50,6 +51,9 @@ if sys.version_info >= (3, 8):
def addModuleCleanup(__function: Callable[_P, object], *args: _P.args, **kwargs: _P.kwargs) -> None: ...
def doModuleCleanups() -> None: ...
if sys.version_info >= (3, 11):
def enterModuleContext(cm: AbstractContextManager[_T]) -> _T: ...
def expectedFailure(test_item: _FT) -> _FT: ...
def skip(reason: str) -> Callable[[_FT], _FT]: ...
def skipIf(condition: object, reason: str) -> Callable[[_FT], _FT]: ...
@@ -211,6 +215,9 @@ class TestCase:
else:
def addCleanup(self, function: Callable[_P, object], *args: _P.args, **kwargs: _P.kwargs) -> None: ...
if sys.version_info >= (3, 11):
def enterContext(self, cm: AbstractContextManager[_T]) -> _T: ...
def doCleanups(self) -> None: ...
if sys.version_info >= (3, 8):
@classmethod
@@ -218,6 +225,10 @@ class TestCase:
@classmethod
def doClassCleanups(cls) -> None: ...
if sys.version_info >= (3, 11):
@classmethod
def enterClassContext(cls, cm: AbstractContextManager[_T]) -> _T: ...
def _formatMessage(self, msg: str | None, standardMsg: str) -> str: ... # undocumented
def _getAssertEqualityFunc(self, first: Any, second: Any) -> Callable[..., None]: ... # undocumented
if sys.version_info < (3, 12):