{"id":5034,"library":"pytest-reportlog","title":"pytest-reportlog","description":"pytest-reportlog is a pytest plugin that provides a modern, extensible replacement for the deprecated `--resultlog` option. It focuses on simplicity and extensibility by writing a stream of machine-readable JSON line objects (JSONL) representing test session events to a specified file. Each line contains a self-contained JSON object corresponding to a testing event, ensuring real-time processing capabilities as the file is guaranteed to be flushed after each line. The current version is 1.0.0, and it is maintained by the pytest-dev team, with releases typically tied to major pytest version compatibility or feature enhancements.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-reportlog","tags":["pytest","plugin","reporting","json","testing"],"install":[{"cmd":"pip install pytest-reportlog","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"pytest-reportlog is a plugin for pytest and requires pytest to function.","package":"pytest","optional":false}],"imports":[{"note":"The plugin is activated automatically when installed and pytest is run.","wrong":null,"symbol":"pytest-reportlog","correct":"This is a pytest plugin, used via command-line options; no direct Python imports are typically needed by users."}],"quickstart":{"code":"# 1. Create a test file (e.g., test_example.py):\n# ---\n# # content of test_example.py\n# def test_ok():\n#     assert 5 + 5 == 10\n#\n# def test_fail():\n#     assert 4 + 4 == 1\n# ---\n\n# 2. Run pytest with the --report-log option:\n# pytest test_example.py --report-log=log.jsonl\n\n# 3. Inspect the generated log file (e.g., with Python):\nimport json\nimport os\n\nlog_file_path = \"log.jsonl\"\n\n# This part simulates running pytest and creating the file.\n# In a real scenario, you'd run the `pytest` command above in your shell.\n# For quickstart execution, we create a dummy file if it doesn't exist.\nif not os.path.exists(log_file_path):\n    with open(log_file_path, \"w\") as f:\n        f.write('{\"pytest_version\": \"8.0.0\", \"$report_type\": \"SessionStart\"}\\n')\n        f.write('{\"nodeid\": \"test_example.py::test_ok\", \"duration\": 0.0001, \"outcome\": \"passed\", \"$report_type\": \"TestReport\"}\\n')\n        f.write('{\"nodeid\": \"test_example.py::test_fail\", \"duration\": 0.0002, \"outcome\": \"failed\", \"$report_type\": \"TestReport\"}\\n')\n        f.write('{\"exitstatus\": 1, \"$report_type\": \"SessionFinish\"}\\n')\n\nprint(f\"Reading first few lines from {log_file_path}:\")\nwith open(log_file_path, \"r\") as f:\n    for i, line in enumerate(f):\n        if i >= 3: # Print first 3 events for brevity\n            break\n        print(json.loads(line))\n\n# Clean up the dummy file\nos.remove(log_file_path)\n","lang":"python","description":"To get started, you simply install the plugin and use the `--report-log=FILE` command-line option when running `pytest`. This will generate a JSONL file containing one JSON object per line, representing various test events."},"warnings":[{"fix":"Upgrade Python to 3.10 or newer, or pin `pytest-reportlog<1.0.0`.","message":"Version 1.0.0 of pytest-reportlog dropped support for Python 3.7, 3.8, and 3.9. Users on these Python versions must either upgrade their Python environment or use an older version of the plugin.","severity":"breaking","affected_versions":"1.0.0 and above"},{"fix":"Replace `--resultlog=FILE` with `--report-log=FILE` in your pytest commands and update any custom parsers to handle the new JSONL format.","message":"pytest-reportlog replaces the `--resultlog` option, which has been deprecated in pytest since version 4.0 and was removed in pytest 6.0. Users of `--resultlog` should migrate to `--report-log` for continued functionality and improved extensibility.","severity":"deprecated","affected_versions":"All versions of pytest where `--resultlog` is deprecated or removed (pytest >= 4.0)"},{"fix":"Design log processing tools to be resilient to additional or modified fields in JSON objects and new `$report_type` values.","message":"The JSON output generated by `--report-log` does not adhere to a strictly defined, versioned schema. While event types are identified by the `$report_type` key, consumers of the log file should be prepared to ignore unknown properties/keys within JSON objects and unrecognized report types for future compatibility.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that any data recorded in `user_properties` (e.g., via `pytest_report_to_serializable`) is JSON-serializable. Consider converting complex objects to string representations or simpler data structures before adding them to `user_properties`.","message":"There have been reported issues regarding the 'weird' handling of unserializable data within `user_properties` when attempting to serialize test reports to JSON. This can lead to unexpected output or serialization errors if complex, non-JSON-serializable objects are passed.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}