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: int | str = 0, 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.- Parameters:
- Return type:
- wait_for(log: Logged, *, timeout: float | None = None) None#
Waits for the expected
logpattern to arrive or thetimeoutto expire.- Parameters:
log (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(log: Logged, *, timeout: float | None = None) None#
Waits asynchronously for the expected
logpattern to arrive or thetimeoutto expire.- Parameters:
log (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(log: Logged) None#
Fails immediately if the expected
logpattern has not arrived.- Parameters:
log (Logged) – The expected log pattern.
- Raises:
AssertionError – If the expected
logpattern has not arrived.- Return type:
None
- assert_not_logged(log: Logged) None#
Fails immediately if the expected
logpattern has arrived.- Parameters:
log (Logged) – The expected log pattern.
- Raises:
AssertionError – If the expected
logpattern has arrived.- Return type:
None
- DEFAULT_LEVEL: ClassVar[int | str] = 0#
The default
levelused bycapturing().This is
logging.NOTSET, specifying that all logs are captured.
- DEFAULT_LOGGER: ClassVar[Logger | str | None] = None#
The default
loggerused bycapturing().This is the root logger.
- DEFAULT_TIMEOUT: ClassVar[float] = 3.0#
The default
timeoutused bywait_for()andawait_for().This is 3 seconds.
- 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.
logot.logged#
- logot.logged.log(level: int | str, msg: str) Logged#
Creates a log pattern representing a log record at the given
levelwith the givenmsg.- Parameters:
level (int | str) – A log level (e.g.
logging.DEBUG) or string name (e.g."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: