Skip to content

Add durations to unittest in 3.12 #10636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions stdlib/unittest/main.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import unittest.case
import unittest.loader
import unittest.result
Expand All @@ -23,22 +24,43 @@ class TestProgram:
progName: str | None
warnings: str | None
testNamePatterns: list[str] | None
def __init__(
self,
module: None | str | ModuleType = "__main__",
defaultTest: str | Iterable[str] | None = None,
argv: list[str] | None = None,
testRunner: type[_TestRunner] | _TestRunner | None = None,
testLoader: unittest.loader.TestLoader = ...,
exit: bool = True,
verbosity: int = 1,
failfast: bool | None = None,
catchbreak: bool | None = None,
buffer: bool | None = None,
warnings: str | None = None,
*,
tb_locals: bool = False,
) -> None: ...
if sys.version_info >= (3, 12):
durations: unittest.result._DurationsType | None
def __init__(
self,
module: None | str | ModuleType = "__main__",
defaultTest: str | Iterable[str] | None = None,
argv: list[str] | None = None,
testRunner: type[_TestRunner] | _TestRunner | None = None,
testLoader: unittest.loader.TestLoader = ...,
exit: bool = True,
verbosity: int = 1,
failfast: bool | None = None,
catchbreak: bool | None = None,
buffer: bool | None = None,
warnings: str | None = None,
*,
tb_locals: bool = False,
durations: unittest.result._DurationsType | None = None,
) -> None: ...
else:
def __init__(
self,
module: None | str | ModuleType = "__main__",
defaultTest: str | Iterable[str] | None = None,
argv: list[str] | None = None,
testRunner: type[_TestRunner] | _TestRunner | None = None,
testLoader: unittest.loader.TestLoader = ...,
exit: bool = True,
verbosity: int = 1,
failfast: bool | None = None,
catchbreak: bool | None = None,
buffer: bool | None = None,
warnings: str | None = None,
*,
tb_locals: bool = False,
) -> None: ...

def usageExit(self, msg: Any = None) -> None: ...
def parseArgs(self, argv: list[str]) -> None: ...
def createTests(self, from_discovery: bool = False, Loader: unittest.loader.TestLoader | None = None) -> None: ...
Expand Down
7 changes: 7 additions & 0 deletions stdlib/unittest/result.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import sys
import unittest.case
from _typeshed import OptExcInfo
from collections.abc import Callable
from typing import Any, TextIO, TypeVar
from typing_extensions import TypeAlias

_F = TypeVar("_F", bound=Callable[..., Any])
_DurationsType: TypeAlias = list[tuple[str, float]]

STDOUT_LINE: str
STDERR_LINE: str
Expand All @@ -22,6 +25,8 @@ class TestResult:
buffer: bool
failfast: bool
tb_locals: bool
if sys.version_info >= (3, 12):
collectedDurations: _DurationsType
def __init__(self, stream: TextIO | None = None, descriptions: bool | None = None, verbosity: int | None = None) -> None: ...
def printErrors(self) -> None: ...
def wasSuccessful(self) -> bool: ...
Expand All @@ -37,3 +42,5 @@ class TestResult:
def addExpectedFailure(self, test: unittest.case.TestCase, err: OptExcInfo) -> None: ...
def addUnexpectedSuccess(self, test: unittest.case.TestCase) -> None: ...
def addSubTest(self, test: unittest.case.TestCase, subtest: unittest.case.TestCase, err: OptExcInfo | None) -> None: ...
if sys.version_info >= (3, 12):
def addDuration(self, test: unittest.case.TestCase, elapsed: float) -> None: ...
62 changes: 49 additions & 13 deletions stdlib/unittest/runner.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import unittest.case
import unittest.result
import unittest.suite
from _typeshed import Incomplete
from collections.abc import Callable, Iterable
from typing import TextIO
from typing_extensions import TypeAlias
Expand All @@ -14,23 +16,57 @@ class TextTestResult(unittest.result.TestResult):
separator2: str
showAll: bool # undocumented
stream: TextIO # undocumented
def __init__(self, stream: TextIO, descriptions: bool, verbosity: int) -> None: ...
if sys.version_info >= (3, 12):
durations: unittest.result._DurationsType | None
def __init__(
self, stream: TextIO, descriptions: bool, verbosity: int, *, durations: unittest.result._DurationsType | None = None
) -> None: ...
else:
def __init__(self, stream: TextIO, descriptions: bool, verbosity: int) -> None: ...

def getDescription(self, test: unittest.case.TestCase) -> str: ...
def printErrorList(self, flavour: str, errors: Iterable[tuple[unittest.case.TestCase, str]]) -> None: ...

class TextTestRunner:
resultclass: _ResultClassType
def __init__(
self,
stream: TextIO | None = None,
descriptions: bool = True,
verbosity: int = 1,
failfast: bool = False,
buffer: bool = False,
resultclass: _ResultClassType | None = None,
warnings: type[Warning] | None = None,
*,
tb_locals: bool = False,
) -> None: ...
# TODO: add `_WritelnDecorator` type
# stream: _WritelnDecorator
stream: Incomplete
descriptions: bool
verbosity: int
failfast: bool
buffer: bool
warnings: str | None
tb_locals: bool

if sys.version_info >= (3, 12):
durations: unittest.result._DurationsType | None
def __init__(
self,
stream: TextIO | None = None,
descriptions: bool = True,
verbosity: int = 1,
failfast: bool = False,
buffer: bool = False,
resultclass: _ResultClassType | None = None,
warnings: str | None = None,
*,
tb_locals: bool = False,
durations: unittest.result._DurationsType | None = None,
) -> None: ...
else:
def __init__(
self,
stream: TextIO | None = None,
descriptions: bool = True,
verbosity: int = 1,
failfast: bool = False,
buffer: bool = False,
resultclass: _ResultClassType | None = None,
warnings: str | None = None,
*,
tb_locals: bool = False,
) -> None: ...

def _makeResult(self) -> unittest.result.TestResult: ...
def run(self, test: unittest.suite.TestSuite | unittest.case.TestCase) -> unittest.result.TestResult: ...
8 changes: 0 additions & 8 deletions tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,9 @@ typing_extensions.Protocol
typing_extensions.SupportsAbs.__type_params__
typing_extensions.SupportsRound.__type_params__
unittest.TestLoader.loadTestsFromModule
unittest.TestProgram.__init__
unittest.TestResult.addDuration
unittest.TextTestResult.__init__
unittest.TextTestRunner.__init__
unittest.load_tests
unittest.loader.TestLoader.loadTestsFromModule
unittest.main.TestProgram.__init__
unittest.mock.NonCallableMock.__new__
unittest.result.TestResult.addDuration
unittest.runner.TextTestResult.__init__
unittest.runner.TextTestRunner.__init__
urllib.request.AbstractHTTPHandler.__init__
urllib.request.HTTPSHandler.__init__
zipfile.Path.glob
Expand Down