### Install logot Python Library with Extras using pip Source: https://logot.readthedocs.io/latest/index.html/_sources/installing.rst This example shows how to install `logot` along with its package 'extras', specifically `pytest`, using `pip`. Package extras ensure compatibility with supported 3rd-party integrations. ```bash pip install 'logot[pytest]' ``` -------------------------------- ### Add logot dependency with Poetry Source: https://logot.readthedocs.io/latest/index.html/installing This command adds `logot` as a project dependency using Poetry, a robust Python packaging and dependency management tool. Poetry automatically handles dependency installation and virtual environment management, simplifying project setup. ```Shell poetry add 'logot' ``` -------------------------------- ### Install Logot with Loguru Extra Source: https://logot.readthedocs.io/latest/index.html/integrations/loguru Instructions for installing `logot` with the `loguru` extra, ensuring all necessary dependencies for `loguru` integration are included. ```Shell pip install 'logot[loguru]' ``` -------------------------------- ### Install logot with pytest extra using pip Source: https://logot.readthedocs.io/latest/index.html/installing This command demonstrates how to install `logot` along with its `pytest` extra using `pip`. Package `extras` provide additional dependencies required for compatibility with specific 3rd-party integrations, ensuring all necessary components are installed. ```Shell pip install 'logot[pytest]' ``` -------------------------------- ### Installing logot with pytest support Source: https://logot.readthedocs.io/latest/index.html/using-pytest Provides the command-line instruction to install the `logot` library along with its `pytest` integration. The `[pytest]` extra ensures that all necessary dependencies for `pytest` plugin functionality are installed. ```Shell pip install 'logot[pytest]' ``` -------------------------------- ### Install Logot with Loguru Extra Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/loguru.rst Provides the command to install `logot` along with its `loguru` extra, ensuring all necessary dependencies are met for `logot` to work correctly with `loguru`. ```bash pip install 'logot[loguru]' ``` -------------------------------- ### Install logot with trio extra Source: https://logot.readthedocs.io/latest/index.html/integrations/trio Instructions on how to install the logot library along with its trio extra dependency using pip, ensuring compatibility for trio integration. ```Shell pip install 'logot[trio]' ``` -------------------------------- ### Install logot Python Library using pip Source: https://logot.readthedocs.io/latest/index.html/_sources/installing.rst This snippet demonstrates the standard way to install the `logot` Python library using the `pip` package manager. It's good practice to perform this installation within a virtual environment to isolate dependencies. ```bash pip install 'logot' ``` -------------------------------- ### Install logot with Pytest Integration Source: https://logot.readthedocs.io/latest/index.html/_sources/using-pytest.rst This Bash command demonstrates how to install the `logot` library, ensuring that the necessary `pytest` integration components are included. The `[pytest]` extra installs all dependencies required for the `logot` pytest plugin. ```bash pip install 'logot[pytest]' ``` -------------------------------- ### Install logot with trio extra (Bash) Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/trio.rst Instructions to install the `logot` library along with its `trio` compatibility extra using pip, ensuring all necessary dependencies for `trio` integration are met. ```bash pip install 'logot[trio]' ``` -------------------------------- ### Install logot with structlog extra Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/structlog.rst This command shows how to install `logot` along with its `structlog` extra using `pip`. This ensures all necessary dependencies for `structlog` integration are installed, enabling seamless log capturing. ```bash pip install 'logot[structlog]' ``` -------------------------------- ### Install logot with structlog extra Source: https://logot.readthedocs.io/latest/index.html/integrations/structlog Command to install `logot` along with the necessary `structlog` integration components. This ensures all dependencies for `structlog` capturing are met. ```Shell pip install 'logot[structlog]' ``` -------------------------------- ### Install logot Python library with pip Source: https://logot.readthedocs.io/latest/index.html/installing This command installs the `logot` Python library using `pip`, the standard Python package installer. It is recommended to install libraries in a virtual environment to isolate dependencies and avoid conflicts with system Python or other projects. ```Shell pip install 'logot' ``` -------------------------------- ### Add logot Python Library using Poetry Source: https://logot.readthedocs.io/latest/index.html/_sources/installing.rst This snippet illustrates how to add the `logot` library using Poetry, a Python packaging and dependency management tool. Poetry simplifies dependency management and automatically handles virtual environments. ```bash poetry add 'logot' ``` -------------------------------- ### Compose Complex Log Patterns with Logot in Python Source: https://logot.readthedocs.io/latest/index.html/_sources/log-pattern-matching.rst This example demonstrates how to combine sequential (">> ") and 'any' ("|") log pattern operators in `logot` to define complex waiting conditions. It waits for an 'App started' log, followed by either an 'App stopped' or 'App crashed!' log, showcasing infinite composability for robust asynchronous testing. ```python from logot import Logot, logged def test_app(logot: Logot) -> None: app.start() logot.wait_for( # Wait for the app to start... logged.info("App started") # ...then wait for the app to stop *or* crash! >> ( logged.info("App stopped") | logged.error("App crashed!") ) ) ``` -------------------------------- ### Capturer.start_capturing: Begin Log Capture Source: https://logot.readthedocs.io/latest/index.html/api/logot Abstract method to start capturing logs for a given `Logot` instance. Implementations should convert captured logs to a `Captured` instance and send them to `Logot.capture()`. ```APIDOC abstractmethod start_capturing(logot: Logot, /, *, level: str | int, name: str | None) -> None Parameters: logot: The Logot instance. level: A log level name (e.g., "DEBUG") or numeric level (e.g., logging.DEBUG). name: A logger name to capture logs from. ``` -------------------------------- ### Manually enable logot trio support (Python) Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/trio.rst Provides examples for manually enabling `trio` support for `logot`. This includes configuring a `Logot` instance with `TrioWaiter` and overriding the `async_waiter` for a single `Logot.await_for` call. ```python from logot.trio import TrioWaiter logot = Logot(async_waiter=TrioWaiter) ``` ```python await logot.await_for(logged.info("App started"), async_waiter=TrioWaiter) ``` -------------------------------- ### Enable trio support in LogotTestCase for unittest Source: https://logot.readthedocs.io/latest/index.html/integrations/trio Provides a code example for enabling trio support within a unittest test case by setting the logot_async_waiter attribute of logot.unittest.LogotTestCase to TrioWaiter from logot.trio. ```Python from logot.trio import TrioWaiter class MyAppTest(LogotTestCase): logot_async_waiter = TrioWaiter ``` -------------------------------- ### Wait for Parallel Log Messages with Logot in Python Source: https://logot.readthedocs.io/latest/index.html/_sources/log-pattern-matching.rst This example utilizes the parallel ("&") operator in `logot` to wait for multiple log messages that can appear in any order. It's useful for scenarios where several independent components start concurrently, ensuring both 'App started' and 'Other app started' logs are eventually received. ```python from logot import Logot, logged def test_app(logot: Logot) -> None: app.start() other_app.start() logot.wait_for( logged.info("App started") & logged.info("Other app started") ) ``` -------------------------------- ### Comparing Log Assertion with unittest.TestCase.assertLogs Source: https://logot.readthedocs.io/latest/index.html/using-unittest This Python example illustrates the equivalent log assertion using `unittest`'s built-in `TestCase.assertLogs()` method. It captures logs within a context manager and then manually verifies the log record's level and message, providing a contrast to `logot`'s approach. ```Python class MyAppTest(TestCase): def test_something(self) -> None: with self.assertLogs(level=logging.DEBUG) as cm: do_something() assert any( record.levelno == logging.INFO and record.message == "Something was done" for record in cm.records ) ``` -------------------------------- ### Configure pytest for structlog capturing (pytest.ini) Source: https://logot.readthedocs.io/latest/index.html/integrations/structlog Example `pytest.ini` configuration to enable `logot.structlog.StructlogCapturer` as the default log capturer for `pytest` tests. This simplifies log capturing setup across test suites. ```INI # pytest.ini or .pytest.ini [pytest] logot_capturer = logot.structlog.StructlogCapturer ``` -------------------------------- ### Configure pytest for logot trio support (INI, TOML) Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/trio.rst Shows how to configure `pytest` to use `logot.trio.TrioWaiter` as the asynchronous waiter, enabling `logot`'s `trio` integration within `pytest` tests. Examples for both `pytest.ini` and `pyproject.toml` are provided. ```ini # pytest.ini or .pytest.ini [pytest] logot_async_waiter = logot.trio.TrioWaiter ``` ```toml # pyproject.toml [tool.pytest.ini_options] logot_async_waiter = "logot.trio.TrioWaiter" ``` -------------------------------- ### Example Daemon Polling Function with Logging Source: https://logot.readthedocs.io/latest/index.html/index Illustrates a `poll_daemon` function designed to run in a separate thread, periodically fetching data and logging its status. This example highlights a scenario where log-based testing is highly beneficial for verifying execution flow. ```python def poll_daemon(app: App) -> None: while not app.stopping: sleep(app.poll_interval) logger.debug("Poll started") try: app.data = app.get("http://is-everything-ok.com/") except HTTPError: logger.exception("Poll error") else: logger.debug("Poll finished") ``` -------------------------------- ### Example Daemon Polling Code with Logging Source: https://logot.readthedocs.io/latest/index.html/_sources/index.rst Illustrates a Python function simulating a daemon that periodically polls an external service. It includes logging for various states and errors, serving as an example of code whose behavior can be effectively tested via its log output, particularly in threaded contexts. ```Python def poll_daemon(app: App) -> None: while not app.stopping: sleep(app.poll_interval) logger.debug("Poll started") try: app.data = app.get("http://is-everything-ok.com/") except HTTPError: logger.exception("Poll error") else: logger.debug("Poll finished") ``` -------------------------------- ### Test Threaded Daemon with Logot.wait_for Source: https://logot.readthedocs.io/latest/index.html/_sources/index.rst Shows how to test the example `poll_daemon` using `logot.wait_for`. This method pauses the test until specific log messages ('Poll started', 'Poll finished') are observed, making it suitable for verifying behavior in threaded or asynchronous code where logs may not appear instantly. ```Python from logot import Logot, logged def test_poll_daemon(logot: Logot) -> None: app.start_poll() for _ in range(3): logot.wait_for(logged.info("Poll started")) logot.wait_for(logged.info("Poll finished")) ``` -------------------------------- ### Asserting Log Messages with %s Placeholder in Python Source: https://logot.readthedocs.io/latest/index.html/_sources/log-message-matching.rst Demonstrates how to use `logot.assert_logged` with a `%s` placeholder to match any string in a log message. This example uses `Logot` and `logged` from the `logot` library to verify log output. ```python from logot import Logot, logged def test_something(logot: Logot) -> None: do_something() logot.assert_logged(logged.info("Something %s done")) ``` -------------------------------- ### Manually enable structlog capturing for Logot instance Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/structlog.rst This example shows how to manually enable `structlog` support when creating a `Logot` instance. By passing `StructlogCapturer` to the `capturer` argument during initialization, the `Logot` instance is configured to capture `structlog` messages. ```python from logot.structlog import StructlogCapturer logot = Logot(capturer=StructlogCapturer) ``` -------------------------------- ### Configure Pytest to Use Loguru Capturer Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/loguru.rst Shows how to enable `loguru` support in `pytest` by setting the `logot_capturer` option. Examples are provided for both `pytest.ini` and `pyproject.toml` configuration files. ```ini # pytest.ini or .pytest.ini [pytest] logot_capturer = logot.loguru.LoguruCapturer ``` ```toml # pyproject.toml [tool.pytest.ini_options] logot_capturer = "logot.loguru.LoguruCapturer" ``` -------------------------------- ### Await Logs in Asynchronous Code with Logot.await_for Source: https://logot.readthedocs.io/latest/index.html/_sources/index.rst Illustrates testing asynchronous Python code using `Logot.await_for`. It shows how to create an asynchronous task and then await a specific log message, 'App started', ensuring the test pauses until the log is received, suitable for `asyncio` based applications. ```Python from logot import Logot, logged async def test_app(logot: Logot) -> None: asyncio.create_task(app.start()) await logot.await_for(logged.info("App started")) ``` -------------------------------- ### Configure pytest for structlog capturing (pyproject.toml) Source: https://logot.readthedocs.io/latest/index.html/integrations/structlog Example `pyproject.toml` configuration to enable `logot.structlog.StructlogCapturer` as the default log capturer for `pytest` tests. This provides an alternative configuration method using the TOML format. ```TOML # pyproject.toml [tool.pytest.ini_options] logot_capturer = "logot.structlog.StructlogCapturer" ``` -------------------------------- ### Enable structlog capturing for pytest Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/structlog.rst These examples illustrate how to configure `pytest` to enable `structlog` support using `logot_capturer`. Configuration can be done in `pytest.ini` (INI format) or `pyproject.toml` (TOML format), automatically integrating `StructlogCapturer`. ```ini # pytest.ini or .pytest.ini [pytest] logot_capturer = logot.structlog.StructlogCapturer ``` ```toml # pyproject.toml [tool.pytest.ini_options] logot_capturer = "logot.structlog.StructlogCapturer" ``` -------------------------------- ### Wait for Sequential Log Messages with Logot in Python Source: https://logot.readthedocs.io/latest/index.html/_sources/log-pattern-matching.rst This snippet illustrates the use of the sequential (">> ") operator in `logot` to assert that log messages arrive in a specific, predefined order. It ensures that 'App started' is logged before 'App stopped', which is crucial for testing workflows with ordered events. ```python from logot import Logot, logged def test_app(logot: Logot) -> None: app.start() logot.wait_for( logged.info("App started") >> logged.info("App stopped") ) ``` -------------------------------- ### Asserting Log Messages with %-style Placeholders in logot Source: https://logot.readthedocs.io/latest/index.html/log-message-matching This Python snippet demonstrates how to use `logot.assert_logged` with `logged.info` to verify that a specific log message containing a `%s` placeholder was emitted. It shows a basic test function setup for log-based testing. ```Python from logot import Logot, logged def test_something(logot: Logot) -> None: do_something() logot.assert_logged(logged.info("Something %s done")) ``` -------------------------------- ### Synchronizing Tests with Logot.wait_for Source: https://logot.readthedocs.io/latest/index.html/index Demonstrates using `Logot.wait_for()` to pause test execution until a specific log message, 'App started', is received. This is crucial for synchronizing tests with asynchronous or threaded operations, ensuring expected events occur. ```python from logot import Logot, logged def test_app(logot: Logot) -> None: app.start() logot.wait_for(logged.info("App started")) ``` -------------------------------- ### Pause test until logs arrive with Logot.await_for (Python) Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/trio.rst Demonstrates how to use `Logot.await_for` within a `trio` asynchronous test to wait for specific log messages, ensuring the application has started before proceeding. The `timeout` argument can be used to configure how long to wait. ```python from logot import Logot, logged async def test_app(logot: Logot) -> None: async with trio.open_nursery() as nursery: nursery.start_soon(app.start()) await logot.await_for(logged.info("App started")) ``` -------------------------------- ### Log Assertion with pytest's caplog Fixture Source: https://logot.readthedocs.io/latest/index.html/_sources/using-pytest.rst This Python example illustrates an alternative approach to log assertion using pytest's built-in `caplog` fixture. It involves manually iterating through `caplog.records` and checking `levelno` and `message` attributes, providing a comparison to the `logot` approach. ```python def test_something(caplog: pytest.LogCaptureFixture) -> None: do_something() assert any( record.levelno == logging.INFO and record.message == "Something was done" for record in caplog.records ) ``` -------------------------------- ### Testing Threaded Code with Logot.wait_for Source: https://logot.readthedocs.io/latest/index.html/index Shows how to test the `poll_daemon` using `logot.wait_for()` to ensure that 'Poll started' and 'Poll finished' log messages are emitted multiple times. This verifies the daemon's correct operation in a threaded context. ```python from logot import Logot, logged def test_poll_daemon(logot: Logot) -> None: app.start_poll() for _ in range(3): logot.wait_for(logged.info("Poll started")) logot.wait_for(logged.info("Poll finished")) ``` -------------------------------- ### Log Assertion using unittest.TestCase.assertLogs() Source: https://logot.readthedocs.io/latest/index.html/_sources/using-unittest.rst This example illustrates how to achieve similar log assertion functionality using the built-in unittest.TestCase.assertLogs() method. It captures logs within a 'with' statement and then manually iterates through the captured records to check for the desired log message and level. ```python class MyAppTest(TestCase): def test_something(self) -> None: with self.assertLogs(level=logging.DEBUG) as cm: do_something() assert any( record.levelno == logging.INFO and record.message == "Something was done" for record in cm.records ) ``` -------------------------------- ### Wait for Logs in Threaded Code with Logot.wait_for Source: https://logot.readthedocs.io/latest/index.html/_sources/index.rst Demonstrates using `Logot.wait_for` to pause a test until a specific log message, such as 'App started', is emitted by a threaded application. This method is essential for testing code where log messages may not appear immediately due to concurrency. ```Python from logot import Logot, logged def test_app(logot: Logot) -> None: app.start() logot.wait_for(logged.info("App started")) ``` -------------------------------- ### Logot Placeholder Reference Source: https://logot.readthedocs.io/latest/index.html/_sources/log-message-matching.rst A comprehensive list of available %-style placeholders for log message matching in the `logot` library, detailing what each placeholder matches. ```APIDOC Placeholder Reference: - %d: Signed integer decimal. - %i: Signed integer decimal. - %o: Signed octal value. - %u: Signed integer decimal. - %x: Signed hexadecimal (lowercase). - %X: Signed hexadecimal (uppercase). - %e: Floating point exponential format (lowercase). - %E: Floating point exponential format (uppercase). - %f: Floating point decimal format (lowercase). - %F: Floating point decimal format (uppercase). - %g: Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. - %G: Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. - %c: Single character. - %r: Any string (non-greedy). - %s: Any string (non-greedy). - %a: Any string (non-greedy). - %%: Escape sequence, results in a % character in the result. ``` -------------------------------- ### Enable logot trio support in unittest.LogotTestCase (Python) Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/trio.rst Demonstrates how to integrate `trio` support into `logot.unittest.LogotTestCase` by setting `logot_async_waiter` to `TrioWaiter`, allowing `unittest` tests to leverage `logot`'s asynchronous waiting capabilities with `trio`. ```python from logot.trio import TrioWaiter class MyAppTest(LogotTestCase): logot_async_waiter = TrioWaiter ``` -------------------------------- ### Manually Enable Loguru Capturer for Logot Instance Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/loguru.rst Explains how to manually enable `loguru` support by passing `LoguruCapturer` directly to the `Logot` constructor when creating a new instance. This sets the capturer for the entire `Logot` object's lifecycle. ```python from logot.loguru import LoguruCapturer logot = Logot(capturer=LoguruCapturer) ``` -------------------------------- ### Capture all logs with Logot Source: https://logot.readthedocs.io/latest/index.html/_sources/log-capturing.rst Demonstrates basic log capturing using `Logot().capturing()` to capture all records from the root logger. It shows how to perform an action and then assert that a specific log message was captured. ```python with Logot().capturing() as logot: do_something() logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### Importing Logot API in Python Source: https://logot.readthedocs.io/latest/index.html/_sources/api/index.rst Demonstrates how to import the `Logot` and `logged` components from the `logot` library. These components are essential for setting up and performing logging assertions within Python tests. ```python from logot import Logot, logged ``` -------------------------------- ### Capture Loguru Logs with Logot Context Manager Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/loguru.rst Demonstrates how to use `LoguruCapturer` with `Logot`'s context manager to capture logs from `loguru` and assert specific log messages within a test or application flow. ```python from logot.loguru import LoguruCapturer with Logot(capturer=LoguruCapturer).capturing() as logot: do_something() logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### Enable Trio support for a Logot instance Source: https://logot.readthedocs.io/latest/index.html/integrations/trio This snippet demonstrates how to enable Trio asynchronous support for a Logot instance by passing `TrioWaiter` as the `async_waiter` argument during initialization. This configures the Logot instance to use Trio for its asynchronous operations. ```python from logot.trio import TrioWaiter logot = Logot(async_waiter=TrioWaiter) ``` -------------------------------- ### Logot Python Module API Documentation Source: https://logot.readthedocs.io/latest/index.html/_sources/api/logot.rst Detailed API documentation for the `logot` module, outlining its main classes and indicating that all their members are documented. This includes classes for log management, capturing, representing captured logs, logged events, and asynchronous waiting. ```APIDOC Module: logot Classes: Logot: Description: Core class for log management. Members: All members are documented. Capturer: Description: Class for capturing log records. Members: All members are documented. Captured: Description: Represents a captured log record. Members: All members are documented. Logged: Description: Represents a logged event. Members: All members are documented. AsyncWaiter: Description: Class for waiting on asynchronous log events. Members: All members are documented. ``` -------------------------------- ### Import Logot API Components Source: https://logot.readthedocs.io/latest/index.html/api/index This snippet demonstrates the standard way to import the `Logot` class and `logged` decorator from the `logot` library, which are essential for log-based testing. ```Python from logot import Logot, logged ``` -------------------------------- ### Capturing Logs with LoguruCapturer Source: https://logot.readthedocs.io/latest/index.html/integrations/loguru Demonstrates how to use `LoguruCapturer` with `Logot` to capture and assert log messages from `loguru` within a test or application context. ```Python from logot.loguru import LoguruCapturer with Logot(capturer=LoguruCapturer).capturing() as logot: do_something() logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### Configure Logot capturing with level and name Source: https://logot.readthedocs.io/latest/index.html/_sources/log-capturing.rst Illustrates how to customize log capturing by specifying a minimum `level` (e.g., `logging.WARNING`) and a logger `name` (e.g., 'app') for the `Logot.capturing` method. This allows for more granular control over which logs are captured. ```python with Logot().capturing(level=logging.WARNING, name="app") as logot: do_something() logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### Capture Logs with Default Settings Source: https://logot.readthedocs.io/latest/index.html/log-capturing Demonstrates basic log capturing using `Logot().capturing()` to capture all records from the root logger. This snippet shows how to perform an action within the capturing context and then assert that a specific log message was captured. ```Python with Logot().capturing() as logot: do_something() logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### logot %-style Log Message Placeholders Reference Source: https://logot.readthedocs.io/latest/index.html/log-message-matching A comprehensive reference of `%`-style placeholders supported by `logot` for flexible log message matching. Each entry details the placeholder and the type of value it matches, aligning with standard Python `logging` module formatting. ```APIDOC Placeholder Reference: - %d: Signed integer decimal. - %i: Signed integer decimal. - %o: Signed octal value. - %u: Signed integer decimal. - %x: Signed hexadecimal (lowercase). - %X: Signed hexadecimal (uppercase). - %e: Floating point exponential format (lowercase). - %E: Floating point exponential format (uppercase). - %f: Floating point decimal format (lowercase). - %F: Floating point decimal format (uppercase). - %g: Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. - %G: Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise. - %c: Single character. - %r: Any string (non-greedy). - %s: Any string (non-greedy). - %a: Any string (non-greedy). - %%: Escape sequence, results in a % character in the result. ``` -------------------------------- ### LogotTestCase Class API Reference Source: https://logot.readthedocs.io/latest/index.html/_sources/api/logot.unittest.rst API documentation for the `LogotTestCase` class within the `logot.unittest` module. It details the class and specifies that all its members are documented, with the exception of the `run` and `debug` methods. ```APIDOC LogotTestCase: Type: Class Module: logot.unittest Members: - All members are included by default. - Excluded from documentation: - run() - debug() Purpose: A base test case class for Logot, likely integrating logging assertions within unittest. ``` -------------------------------- ### logot.trio.TrioWaiter Class Reference Source: https://logot.readthedocs.io/latest/index.html/api/logot.trio Defines the `TrioWaiter` class, an asynchronous waiter implementation for the `logot` library, specifically designed for integration with the `trio` asynchronous framework. ```APIDOC class logot.trio.TrioWaiter Description: A logot.AsyncWaiter implementation for trio. ``` -------------------------------- ### LoggingCapturer Class API Reference Source: https://logot.readthedocs.io/latest/index.html/_sources/api/logot.logging.rst API documentation for the `LoggingCapturer` class, which is part of the `logot.logging` module. This entry outlines the expected structure of its API, including methods and properties, as referenced by the Sphinx `autoclass` directive. ```APIDOC LoggingCapturer Class: Description: A class designed for capturing and managing logging output. Methods: (Specific methods like `__init__`, `capture`, `release` would be detailed here if available in source documentation) Properties: (Specific properties would be detailed here if available in source documentation) ``` -------------------------------- ### Enable Loguru support for a Logot instance (Python) Source: https://logot.readthedocs.io/latest/index.html/integrations/loguru This snippet demonstrates how to enable Loguru support globally for a Logot instance. By passing LoguruCapturer to the Logot constructor, all subsequent logging operations through this Logot instance will utilize Loguru for capturing. ```Python from logot.loguru import LoguruCapturer logot = Logot(capturer=LoguruCapturer) ``` -------------------------------- ### Asserting Log Messages with Logot Source: https://logot.readthedocs.io/latest/index.html/index Demonstrates a basic test using `logot` to assert that a specific log message was emitted after an action. It shows how to use `Logot` and `logged.info` to verify log output in a test function. ```python from logot import Logot, logged def test_something(logot: Logot) -> None: do_something() logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### Available Fixtures in logot Pytest Plugin Source: https://logot.readthedocs.io/latest/index.html/_sources/using-pytest.rst This API documentation lists the specific fixtures provided by the `logot` pytest plugin. Each entry details the fixture's name, type, and a brief description of its purpose, enabling direct access to `logot` functionalities and configuration values within tests. ```APIDOC logot: logot.Logot Description: An initialized logot.Logot instance with log capturing enabled. logot_level: str | int Description: The level used for automatic log capturing. logot_name: str | None Description: The name used for automatic log capturing. logot_capturer: Callable[[], Capturer] Description: The default capturer for the logot fixture. logot_timeout: float Description: The default timeout (in seconds) for the logot fixture. logot_async_waiter: Callable[[], AsyncWaiter] Description: The default async_waiter for the logot fixture. ``` -------------------------------- ### Logot Public API Modules Source: https://logot.readthedocs.io/latest/index.html/api/index This section lists the public modules available within the `logot` library's API, each providing specific functionalities for log-based testing and integrations. ```APIDOC Modules: - logot - logot.asyncio - logot.logged - logot.logging - logot.loguru - logot.structlog - logot.trio - logot.unittest ``` -------------------------------- ### TrioWaiter Class API Reference Source: https://logot.readthedocs.io/latest/index.html/_sources/api/logot.trio.rst API documentation for the `TrioWaiter` class, which is part of the `logot.trio` module. This class is likely used for specific waiting operations within a Trio asynchronous context. ```APIDOC class TrioWaiter ``` -------------------------------- ### Enable Loguru Support in Unittest Source: https://logot.readthedocs.io/latest/index.html/integrations/loguru Illustrates how to configure `loguru` support within a `logot.unittest.LogotTestCase` by setting the `logot_capturer` attribute for log capturing. ```Python from logot.loguru import LoguruCapturer class MyAppTest(LogotTestCase): logot_capturer = LoguruCapturer ``` -------------------------------- ### StructlogCapturer Class API Reference Source: https://logot.readthedocs.io/latest/index.html/_sources/api/logot.structlog.rst API documentation for the `StructlogCapturer` class within the `logot.structlog` module, detailing its structure and usage. ```APIDOC Module: logot.structlog Class: StructlogCapturer ``` -------------------------------- ### Enable Loguru Capturer for a Single Logot Capturing Call Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/loguru.rst Demonstrates how to apply `LoguruCapturer` for a specific `Logot.capturing` call, providing granular control over log capturing for individual code blocks without affecting the global `Logot` instance. ```python with Logot().capturing(capturer=LoguruCapturer) as logot: do_something() ``` -------------------------------- ### Available pytest-logot Plugin Fixtures Source: https://logot.readthedocs.io/latest/index.html/using-pytest The logot pytest plugin provides several fixtures to facilitate testing with log capturing. These fixtures offer access to the logot instance and allow customization of log capturing parameters within tests. ```APIDOC Fixture: logot Type: logot.Logot Description: An initialized logot.Logot instance with log capturing enabled. Fixture: logot_level Type: str | int Description: The level used for automatic log capturing. Fixture: logot_name Type: str | None Description: The name used for automatic log capturing. Fixture: logot_capturer Type: Callable[[], Capturer] Description: The default capturer for the logot fixture. Fixture: logot_timeout Type: float Description: The default timeout (in seconds) for the logot fixture. Fixture: logot_async_waiter Type: Callable[[], AsyncWaiter] Description: The default async_waiter for the logot fixture. ``` -------------------------------- ### Configure Log Capturing with Level and Name Source: https://logot.readthedocs.io/latest/index.html/log-capturing Illustrates how to customize log capturing by specifying a minimum `level` (e.g., `logging.WARNING`) and a logger `name` (e.g., 'app') using `Logot().capturing()`. This allows for more granular control over which logs are captured, preventing the capture of unwanted log records. ```Python with Logot().capturing(level=logging.WARNING, name="app") as logot: do_something() logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### APIDOC: logot.unittest.LogotTestCase Class Reference Source: https://logot.readthedocs.io/latest/index.html/api/logot.unittest Detailed API documentation for the `logot.unittest.LogotTestCase` class, which extends `unittest.TestCase` to provide automatic log capturing capabilities. It includes descriptions of its constructor and key properties used for configuring log assertion behavior. ```APIDOC class logot.unittest.LogotTestCase(methodName='runTest') Description: A unittest.TestCase subclass with automatic log capturing. Properties: logot: Logot Description: An initialized logot.Logot instance with log capturing enabled. Use this to make log assertions in your tests. logot_level: ClassVar[str | int] = 'DEBUG' Description: The level used for automatic log capturing. Defaults to logot.Logot.DEFAULT_LEVEL. logot_name: ClassVar[str | None] = None Description: The name used for automatic log capturing. Defaults to logot.Logot.DEFAULT_NAME. logot_capturer: ClassVar[Callable[[], Capturer]] = logot.logging.LoggingCapturer Description: The default capturer for LogotTestCase.logot. Defaults to logot.Logot.DEFAULT_CAPTURER. logot_timeout: ClassVar[float] = 3.0 Description: The default timeout (in seconds) for LogotTestCase.logot. Defaults to logot.Logot.DEFAULT_TIMEOUT. logot_async_waiter: ClassVar[Callable[[], AsyncWaiter]] = logot.asyncio.AsyncioWaiter Description: The default async_waiter for LogotTestCase.logot. Defaults to logot.Logot.DEFAULT_ASYNC_WAITER. ``` -------------------------------- ### Testing Asynchronous Code with Logot.await_for() Source: https://logot.readthedocs.io/latest/index.html/index Demonstrates how to test asynchronous Python code by pausing the test execution until expected log messages arrive using `Logot.await_for()`. It shows creating an asynchronous task and then waiting for a specific info log, with an option to configure a timeout. ```python from logot import Logot, logged async def test_app(logot: Logot) -> None: asyncio.create_task(app.start()) await logot.await_for(logged.info("App started")) ``` -------------------------------- ### logot.loguru.LoguruCapturer Class Definition Source: https://logot.readthedocs.io/latest/index.html/api/logot.loguru Documentation for the `LoguruCapturer` class, an implementation of `logot.Capturer` specifically designed for use with the `loguru` logging library. It provides the necessary interface for `logot` to capture log messages from `loguru`. ```APIDOC class logot.loguru.LoguruCapturer A logot.Capturer implementation for loguru. ``` -------------------------------- ### Enable Loguru Capturer in Unittest LogotTestCase Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/loguru.rst Illustrates how to integrate `LoguruCapturer` into a `unittest` test suite by assigning it to the `logot_capturer` class attribute within a `LogotTestCase` subclass. ```python from logot.loguru import LoguruCapturer class MyAppTest(LogotTestCase): logot_capturer = LoguruCapturer ``` -------------------------------- ### LogotTestCase Integration for Log Assertions Source: https://logot.readthedocs.io/latest/index.html/_sources/using-unittest.rst This snippet demonstrates how to use logot.unittest.LogotTestCase to capture and assert logs within a unittest test case. It shows self.logot.assert_logged with logged.info to verify specific log messages, providing a cleaner syntax for log testing. ```python from logot import logged from logot.unittest import LogotTestCase class MyAppTest(LogotTestCase): def test_something(self) -> None: do_something() self.logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### Enable Loguru support for a single Logot capturing call (Python) Source: https://logot.readthedocs.io/latest/index.html/integrations/loguru This snippet illustrates how to enable Loguru support for a specific Logot capturing context using a 'with' statement. The LoguruCapturer is passed to the Logot.capturing() method, ensuring that logs generated within the 'with' block are captured by Loguru. ```Python with Logot().capturing(capturer=LoguruCapturer) as logot: do_something() ``` -------------------------------- ### AsyncioWaiter Class API Reference Source: https://logot.readthedocs.io/latest/index.html/_sources/api/logot.asyncio.rst API documentation for the `AsyncioWaiter` class, part of the `logot.asyncio` module. This class is designed for managing asynchronous waiting mechanisms. Further details on its methods and properties would typically follow this declaration. ```APIDOC Class: AsyncioWaiter Module: logot.asyncio Description: A class for handling asynchronous waiting operations. Methods: (Details not provided in snippet) Properties: (Details not provided in snippet) ``` -------------------------------- ### Configure pytest-logot Plugin with CLI and Configuration Options Source: https://logot.readthedocs.io/latest/index.html/using-pytest These options allow users to customize the behavior of automatic log capturing within pytest when using the logot plugin. CLI options take precedence over configuration file settings if both are provided. ```APIDOC Option: --logot-level, logot_level Description: The level used for automatic log capturing. Default: logot.Logot.DEFAULT_LEVEL Option: --logot-name, logot_name Description: The name used for automatic log capturing. Default: logot.Logot.DEFAULT_NAME Option: --logot-capturer, logot_capturer Description: The default capturer for the logot fixture. Default: logot.Logot.DEFAULT_CAPTURER Option: --logot-timeout, logot_timeout Description: The default timeout (in seconds) for the logot fixture. Default: logot.Logot.DEFAULT_TIMEOUT Option: --logot-async-waiter, logot_async_waiter Description: The default async_waiter for the logot fixture. Default: logot.Logot.DEFAULT_ASYNC_WAITER ``` -------------------------------- ### LoguruCapturer Class API Reference Source: https://logot.readthedocs.io/latest/index.html/_sources/api/logot.loguru.rst API documentation for the `LoguruCapturer` class within the `logot.loguru` module. This class is likely used for capturing logs from the Loguru logging library. ```APIDOC class LoguruCapturer: # Further details (methods, properties) would be extracted if available in source documentation. ``` -------------------------------- ### Enable structlog support for Logot instance Source: https://logot.readthedocs.io/latest/index.html/integrations/structlog This snippet demonstrates how to enable structlog support for a Logot instance by assigning StructlogCapturer to its capturer attribute. This configuration applies globally to the Logot instance. ```Python from logot.structlog import StructlogCapturer logot = Logot(capturer=StructlogCapturer) ``` -------------------------------- ### Configure Pytest for Loguru Integration Source: https://logot.readthedocs.io/latest/index.html/integrations/loguru Shows how to enable `loguru` support in `pytest` by setting the `logot_capturer` option in either `pytest.ini` or `pyproject.toml`. ```INI # pytest.ini or .pytest.ini [pytest] logot_capturer = logot.loguru.LoguruCapturer ``` ```TOML # pyproject.toml [tool.pytest.ini_options] logot_capturer = "logot.loguru.LoguruCapturer" ``` -------------------------------- ### Enable structlog support for Logot.capturing() context Source: https://logot.readthedocs.io/latest/index.html/integrations/structlog This snippet shows how to enable structlog support for a single Logot.capturing() call using a context manager. This approach is useful for applying structlog integration only for a specific block of code or test. ```Python with Logot().capturing(capturer=StructlogCapturer) as logot: do_something() ``` -------------------------------- ### Matching parallel log patterns with Logot Source: https://logot.readthedocs.io/latest/index.html/log-pattern-matching Shows how to use the `&` operator in Logot to wait for multiple logs that can arrive in any order. Both specified log messages must be received, but their sequence does not matter. ```python from logot import Logot, logged def test_app(logot: Logot) -> None: app.start() other_app.start() logot.wait_for( logged.info("App started") & logged.info("Other app started") ) ``` -------------------------------- ### Enable Trio support for a single Logot.await_for call Source: https://logot.readthedocs.io/latest/index.html/integrations/trio This snippet shows how to enable Trio asynchronous support for a specific `Logot.await_for()` call. By providing `TrioWaiter` to the `async_waiter` argument, this particular await operation will utilize Trio for its asynchronous waiting mechanism, overriding any default or instance-level configuration. ```python await logot.await_for(logged.info("App started"), async_waiter=TrioWaiter) ``` -------------------------------- ### Matching sequential log patterns with Logot Source: https://logot.readthedocs.io/latest/index.html/log-pattern-matching Illustrates the use of the `>>` operator in Logot to wait for logs that must arrive in a specific sequential order. This ensures that the first log message is received before the second one. ```python from logot import Logot, logged def test_app(logot: Logot) -> None: app.start() logot.wait_for( logged.info("App started") >> logged.info("App stopped") ) ``` -------------------------------- ### Integrate structlog capturer with unittest Source: https://logot.readthedocs.io/latest/index.html/integrations/structlog Demonstrates how to set `logot.structlog.StructlogCapturer` as the `logot_capturer` for `unittest` test cases by subclassing `LogotTestCase`. This enables `structlog` log capturing within `unittest` environments. ```Python from logot.structlog import StructlogCapturer class MyAppTest(LogotTestCase): logot_capturer = StructlogCapturer ``` -------------------------------- ### Matching complex log patterns with Logot Source: https://logot.readthedocs.io/latest/index.html/log-pattern-matching Demonstrates how to use Logot's `wait_for` method with nested log pattern operators (`>>` for sequential, `|` for any) to match logs that may arrive in an unpredictable order, suitable for threaded or asynchronous applications. Parentheses are used to define complex patterns. ```python from logot import Logot, logged def test_app(logot: Logot) -> None: app.start() logot.wait_for( # Wait for the app to start... logged.info("App started") # ...then wait for the app to stop *or* crash! >> ( logged.info("App stopped") | logged.error("App crashed!") ) ) ``` -------------------------------- ### logot.logging.LoggingCapturer Class Definition Source: https://logot.readthedocs.io/latest/index.html/api/logot.logging Documentation for the `LoggingCapturer` class, which serves as the default `logot.Capturer` implementation for Python's standard `logging` module. ```APIDOC class logot.logging.LoggingCapturer Description: A logot.Capturer implementation for logging. Note: This is the default logot.Capturer implementation. ``` -------------------------------- ### Logot Class API Definition Source: https://logot.readthedocs.io/latest/index.html/api/logot Defines the `logot.Logot` class, the core API for log capturing and waiting. It includes constructor parameters, class-level defaults, and instance properties that control its behavior, such as the log capturer, timeout duration, and asynchronous waiter. ```APIDOC class logot.Logot( capturer: Callable[[], Capturer] = logot.logging.LoggingCapturer, timeout: float = 3.0, async_waiter: Callable[[], AsyncWaiter] = logot.asyncio.AsyncioWaiter ) Description: The main logot API for capturing and waiting for logs. Parameters: capturer: See Logot.capturer. timeout: See Logot.timeout. async_waiter: See Logot.async_waiter. Class Variables: DEFAULT_LEVEL: ClassVar[str | int] = 'DEBUG' Description: The default `level` used by `capturing()`. DEFAULT_NAME: ClassVar[str | None] = None Description: The default `name` used by `capturing()`. Defaults to `None`, representing the root logger. DEFAULT_CAPTURER: ClassVar[Callable[[], Capturer]] = logot.logging.LoggingCapturer Description: The default `capturer` for new `Logot` instances. DEFAULT_TIMEOUT: ClassVar[float] = 3.0 Description: The default `timeout` (in seconds) for new `Logot` instances. DEFAULT_ASYNC_WAITER: ClassVar[Callable[[], AsyncWaiter]] = logot.asyncio.AsyncioWaiter Description: The default `async_waiter` for new `Logot` instances. Instance Properties: capturer: Callable[[], Capturer] Description: The default `capturer` used by `capturing()`. This is for integration with 3rd-party logging frameworks. Defaults to `Logot.DEFAULT_CAPTURER`. timeout: float Description: The default `timeout` (in seconds) for calls to `wait_for()` and `await_for()`. Defaults to `Logot.DEFAULT_TIMEOUT`. async_waiter: Callable[[], AsyncWaiter] Description: The default `async_waiter` for calls to `await_for()`. ``` -------------------------------- ### Capture structlog logs with Logot in Python Source: https://logot.readthedocs.io/latest/index.html/_sources/integrations/structlog.rst This snippet demonstrates how to capture `structlog` messages using `logot` by initializing `Logot` with `StructlogCapturer`. It shows a typical usage pattern within a `with` statement to assert a logged info message. ```python from logot.structlog import StructlogCapturer with Logot(capturer=StructlogCapturer).capturing() as logot: do_something() logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### Configure logot Pytest Plugin Options Source: https://logot.readthedocs.io/latest/index.html/_sources/using-pytest.rst This API documentation outlines the configuration options available for the `logot` pytest plugin. These options can be set via command-line arguments or `pytest` configuration files to control log capturing level, name, capturer, timeout, and async waiter behavior. ```APIDOC logot_level: Description: The level used for automatic log capturing. Defaults: logot.Logot.DEFAULT_LEVEL logot_name: Description: The name used for automatic log capturing. Defaults: logot.Logot.DEFAULT_NAME logot_capturer: Description: The default capturer for the logot fixture. Defaults: logot.Logot.DEFAULT_CAPTURER logot_timeout: Description: The default timeout (in seconds) for the logot fixture. Defaults: logot.Logot.DEFAULT_TIMEOUT logot_async_waiter: Description: The default async_waiter for the logot fixture. Defaults: logot.Logot.DEFAULT_ASYNC_WAITER ``` -------------------------------- ### Asserting Logs with logot.unittest.LogotTestCase Source: https://logot.readthedocs.io/latest/index.html/using-unittest This Python code demonstrates how to integrate `logot` with `unittest` by inheriting from `LogotTestCase`. It shows how to use the `self.logot` attribute to assert that a specific log message was emitted during a test. ```Python from logot import logged from logot.unittest import LogotTestCase class MyAppTest(LogotTestCase): def test_something(self) -> None: do_something() self.logot.assert_logged(logged.info("Something was done")) ``` -------------------------------- ### Testing Synchronous Code with Logot.assert_logged() Source: https://logot.readthedocs.io/latest/index.html/index Illustrates how to test synchronous Python code by immediately failing the test if expected log messages are not present using `Logot.assert_logged()`. This method provides immediate feedback compared to `Logot.wait_for()` which waits for a timeout. ```python from logot import Logot, logged def test_something(logot: Logot) -> None: do_something() logot.assert_logged(logged.info("Something was done")) ```