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_levelThe
levelused for automatic log capturing.Defaults to
logot.Logot.DEFAULT_LEVEL.--logot-name,logot_nameThe
nameused for automatic log capturing.Defaults to
logot.Logot.DEFAULT_NAME.--logot-capturer,logot_capturerThe default
capturerfor thelogotfixture.Defaults to
logot.Logot.DEFAULT_CAPTURER.--logot-timeout,logot_timeoutThe default
timeout(in seconds) for thelogotfixture.Defaults to
logot.Logot.DEFAULT_TIMEOUT.--logot-async-waiter,logot_async_waiterThe default
async_waiterfor thelogotfixture.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.LogotAn initialized
logot.Logotinstance with log capturing enabled.logot_level:str|intThe
levelused for automatic log capturing.logot_name:str|NoneThe
nameused for automatic log capturing.logot_capturer:Callable[[],Capturer]The default
capturerfor thelogotfixture.logot_timeout:floatThe default
timeout(in seconds) for thelogotfixture.logot_async_waiter:Callable[[],AsyncWaiter]The default
async_waiterfor thelogotfixture.