{"library":"pytest-structlog","title":"pytest-structlog","description":"pytest-structlog is a pytest plugin that provides structured logging assertions for structlog. It integrates a 'log' fixture into your tests, allowing you to capture and make assertions against structlog events. The library is currently at version 1.2 and maintains a fairly active release cadence, with new versions typically released monthly or quarterly.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install pytest-structlog"],"cli":null},"imports":["from pytest_structlog import StructuredLogCapture","import structlog; logger = structlog.get_logger()"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import structlog\nfrom pytest_structlog import StructuredLogCapture\n\n# your_lib.py (or code under test)\nlogger = structlog.get_logger()\n\ndef do_something():\n    logger.info(\"Starting process\", task_id=\"abc-123\")\n    for i in range(2):\n        logger.debug(\"Step complete\", step=i)\n    logger.warning(\"Process finished with warnings\", result=\"partial\", count=2)\n\n# test_your_lib.py\ndef test_do_something(log: StructuredLogCapture):\n    assert len(log.events) == 0 # No logs captured initially\n\n    do_something()\n\n    # Assert on specific event counts\n    assert log.count(\"Starting process\", level=\"info\") == 1\n    assert log.count(\"Step complete\", level=\"debug\") == 2\n\n    # Assert on individual events with context\n    assert log.has(\"Starting process\", task_id=\"abc-123\")\n    assert log.has(\"Step complete\", step=0)\n    assert log.has(\"Step complete\", step=1)\n    assert log.has(\"Process finished with warnings\", result=\"partial\", count=2, level=\"warning\")\n\n    # You can also inspect all captured events directly\n    expected_events = [\n        log.info(\"Starting process\", task_id=\"abc-123\"),\n        log.debug(\"Step complete\", step=0),\n        log.debug(\"Step complete\", step=1),\n        log.warning(\"Process finished with warnings\", result=\"partial\", count=2)\n    ]\n    assert log.events == expected_events","lang":"python","description":"This quickstart demonstrates how to use the `log` fixture provided by pytest-structlog. It shows how to capture structlog events from a function under test and then assert their presence and content using `log.events`, `log.has()`, and `log.count()`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"1.2","pypi_latest":"1.2","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.7,"avg_import_s":0.64,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.52,"mem_mb":13.4,"disk_size":"31.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0.36,"mem_mb":13.4,"disk_size":"32M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.68,"mem_mb":15.1,"disk_size":"34.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0.63,"mem_mb":15.1,"disk_size":"35M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.92,"mem_mb":17.9,"disk_size":"25.8M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0.81,"mem_mb":17.9,"disk_size":"26M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.87,"mem_mb":17.8,"disk_size":"25.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0.76,"mem_mb":17.8,"disk_size":"26M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.45,"mem_mb":12.9,"disk_size":"30.6M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pytest-structlog","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.1,"import_time_s":0.4,"mem_mb":12.9,"disk_size":"31M"}]}}