Using with pytest#

logot includes a pytest plugin.

The logot fixture automatically captures logs during tests and can be used to make log assertions:

from logot import Logot, logged

def test_something(logot: Logot) -> None:
   do_something()
   logot.assert_logged(logged.info("Something was done"))

Installing#

Ensure logot is installed alongside a compatible pytest version by adding the pytest extra:

pip install 'logot[pytest]'

See also

See Installing package extras usage guide.

Configuring#

Use the following CLI and configuration options to configure the pytest plugin:

--logot-level, logot_level

The level used for automatic log capturing.

Defaults to logot.Logot.DEFAULT_LEVEL.

--logot-logger, logot_logger

The logger used for automatic log capturing.

Defaults to logot.Logot.DEFAULT_LOGGER.

--logot-capturer, logot_capturer

The default capturer for the logot fixture.

Defaults to logot.Logot.DEFAULT_CAPTURER.

--logot-timeout, logot_timeout

The default timeout (in seconds) for the logot fixture.

Defaults to logot.Logot.DEFAULT_TIMEOUT.

--logot-async-waiter, logot_async_waiter

The default async_waiter for the logot fixture.

Defaults to logot.Logot.DEFAULT_ASYNC_WAITER.

Note

When both CLI and configuration options are given, the CLI option takes precidence.

Available fixtures#

The following fixtures are available in the pytest plugin:

logot: logot.Logot

An initialized logot.Logot instance with log capturing enabled.

logot_level: str | int

The level used for automatic log capturing.

logot_logger: str | None

The logger used for automatic log capturing.

logot_capturer: Callable [[], Capturer ]

The default capturer for the logot fixture.

logot_timeout: float

The default timeout (in seconds) for the logot fixture.

logot_async_waiter: Callable [[], AsyncWaiter ]

The default async_waiter for the logot fixture.