Add unittest.AssertNoLogs (#6414)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Alex Waygood
2021-11-28 10:30:19 +00:00
committed by GitHub
parent 0131f4b868
commit 77725c5ed3

View File

@@ -30,6 +30,7 @@ if sys.version_info >= (3, 9):
_E = TypeVar("_E", bound=BaseException)
_FT = TypeVar("_FT", bound=Callable[..., Any])
_L = TypeVar("_L", None, _LoggingWatcher)
if sys.version_info >= (3, 8):
def addModuleCleanup(__function: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ...
@@ -128,7 +129,13 @@ class TestCase:
expected_regex: str | bytes | Pattern[str] | Pattern[bytes],
msg: Any = ...,
) -> _AssertWarnsContext: ...
def assertLogs(self, logger: str | logging.Logger | None = ..., level: int | str | None = ...) -> _AssertLogsContext: ...
def assertLogs(
self, logger: str | logging.Logger | None = ..., level: int | str | None = ...
) -> _AssertLogsContext[_LoggingWatcher]: ...
if sys.version_info >= (3, 10):
def assertNoLogs(
self, logger: str | logging.Logger | None = ..., level: int | str | None = ...
) -> _AssertLogsContext[None]: ...
@overload
def assertAlmostEqual(
self, first: float, second: float, places: int | None = ..., msg: Any = ..., delta: float | None = ...
@@ -267,15 +274,12 @@ class _AssertWarnsContext:
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
class _AssertLogsContext:
class _AssertLogsContext(Generic[_L]):
LOGGING_FORMAT: str
records: list[logging.LogRecord]
output: list[str]
def __init__(self, test_case: TestCase, logger_name: str, level: int) -> None: ...
if sys.version_info >= (3, 10):
def __enter__(self) -> _LoggingWatcher | None: ...
else:
def __enter__(self) -> _LoggingWatcher: ...
def __enter__(self) -> _L: ...
def __exit__(
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...