API reference#
Import the logot API in your tests:
from logot import Logot, logged
logot#
- class logot.Logot(*, timeout: float = 3.0)#
The main
logotAPI for capturing and waiting for logs.See also
See Log-based testing 🪵 usage guide.
- Parameters:
timeout (float) – The default timeout (in seconds) for calls to
wait_for()andawait_for(). Defaults toDEFAULT_TIMEOUT.
- capturing(*, level: str | int = 'DEBUG', logger: Logger | str | None = None) AbstractContextManager[Logot]#
Captures logs emitted at the given
levelby the givenloggerfor the duration of the context.If the given
loggerlevel is less verbose than the requestedlevel, it will be temporarily adjusted to the requestedlevelfor the duration of the context.See also
See Log capturing usage guide.
- Parameters:
level (str | int) – A log level name (e.g.
"DEBUG") or numeric constant (e.g.logging.DEBUG). Defaults toDEFAULT_LEVEL.logger (Logger | str | None) – A logger or logger name to capture logs from. Defaults to
DEFAULT_LOGGER.
- Return type:
- capture(captured: Captured) None#
Adds the given captured log record to the internal capture queue.
Any waiters blocked on
wait_for()toawait_for()will be notified and wake up if their log pattern is satisfied.Note
This method is for integration with 3rd-party logging frameworks. It is not generally used when writing tests.
See also
See Capturing 3rd-party logs usage guide.
- Parameters:
captured (Captured) – The captured log.
- Return type:
None
- wait_for(logged: Logged, *, timeout: float | None = None) None#
Waits for the expected
logpattern to arrive or thetimeoutto expire.- Parameters:
logged (Logged) – The expected log pattern.
timeout (float | None) – How long to wait (in seconds) before failing the test. Defaults to the
timeoutpassed toLogot.
- Raises:
AssertionError – If the expected
logpattern does not arrive withintimeoutseconds.- Return type:
None
- async await_for(logged: Logged, *, timeout: float | None = None) None#
Waits asynchronously for the expected
logpattern to arrive or thetimeoutto expire.- Parameters:
logged (Logged) – The expected log pattern.
timeout (float | None) – How long to wait (in seconds) before failing the test. Defaults to the
timeoutpassed toLogot.
- Raises:
AssertionError – If the expected
logpattern does not arrive withintimeoutseconds.- Return type:
None
- assert_logged(logged: Logged) None#
Fails immediately if the expected
logpattern has not arrived.- Parameters:
logged (Logged) – The expected log pattern.
- Raises:
AssertionError – If the expected
logpattern has not arrived.- Return type:
None
- assert_not_logged(logged: Logged) None#
Fails immediately if the expected
logpattern has arrived.- Parameters:
logged (Logged) – The expected log pattern.
- Raises:
AssertionError – If the expected
logpattern has arrived.- Return type:
None
- DEFAULT_LEVEL: ClassVar[str | int] = 'DEBUG'#
The default
levelused bycapturing().
- DEFAULT_LOGGER: ClassVar[Logger | str | None] = None#
The default
loggerused bycapturing().This is the root logger.
- DEFAULT_TIMEOUT: ClassVar[float] = 3.0#
The default
timeout(in seconds) used bywait_for()andawait_for().
- class logot.Logged#
A log pattern passed to
Logot.wait_for(),Logot.await_for()and similar APIs.Important
Loggedinstances are immutable and can be reused between tests.Note
This is an abstract class and cannot be instantiated. Use the helpers in
logot.loggedto create log patterns.See also
See Log pattern matching usage guide.
- class logot.Captured(levelname: str, msg: str, *, levelno: int)#
A captured log record.
Send
Capturedlogs toLogot.capture()to integrate with 3rd-party logging frameworksNote
This class is for integration with 3rd-party logging frameworks. It is not generally used when writing tests.
See also
See Capturing 3rd-party logs usage guide.
- Parameters:
levelname (str) – The log level name (e.g.
"DEBUG").msg (str) – The log message.
levelno (int) – The log level number (e.g.
logging.DEBUG).
- levelno: int#
The log level number (e.g.
logging.DEBUG).
logot.logged#
- logot.logged.log(level: str | int, msg: str) Logged#
Creates a log pattern representing a log record at the given
levelwith the givenmsg.- Parameters:
level (str | int) – A log level name (e.g.
"DEBUG") or numeric constant (e.g.logging.DEBUG).msg (str) – A log message pattern.
- Return type:
- logot.logged.debug(msg: str) Logged#
Creates a log pattern representing a log record at
DEBUGlevel with the givenmsg.- Parameters:
msg (str) – A log message pattern.
- Return type:
- logot.logged.info(msg: str) Logged#
Creates a log pattern representing a log record at
INFOlevel with the givenmsg.- Parameters:
msg (str) – A log message pattern.
- Return type:
- logot.logged.warning(msg: str) Logged#
Creates a log pattern representing a log record at
WARNINGlevel with the givenmsg.- Parameters:
msg (str) – A log message pattern.
- Return type:
- logot.logged.error(msg: str) Logged#
Creates a log pattern representing a log record at
ERRORlevel with the givenmsg.- Parameters:
msg (str) – A log message pattern.
- Return type:
- logot.logged.critical(msg: str) Logged#
Creates a log pattern representing a log record at
CRITICALlevel with the givenmsg.- Parameters:
msg (str) – A log message pattern.
- Return type: