|View source on GitHub|
A context manager for testing logging and warning events.
cirq.testing.assert_logs( *matches, count: Optional[int] = 1, min_level: int = logging.WARNING, max_level: int = logging.CRITICAL, capture_warnings: bool = True ) -> Iterator[List[logging.LogRecord]]
To use this one wraps the code that is to be tested for log events within the context of this method's return value:
with assert_logs(count=2, 'first_match', 'second_match') as logs: <code that produces python logs>
This captures the logging that occurs in the context of the with statement,
asserts that the number of logs is equal to
count, and then asserts that
all of the strings in
matches appear in the messages of the logs.
Further, the captured logs are accessible as
logs and further testing
can be done beyond these simple asserts.
|A ContextManager that can be entered into which captures the logs for code executed within the entered context. This ContextManager checks that the asserts for the logs are true on exit.|