{"id":9246,"library":"pytest-json","title":"pytest-json","description":"pytest-json is a plugin for the pytest testing framework that generates JSON reports of test results. Last updated in January 2016, its latest version is 0.4.0. The project appears to be unmaintained, with limited Python and pytest version compatibility. It does not have an active release cadence.","status":"abandoned","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/mattcl/pytest-json","tags":["pytest","testing","json","reporting","plugin"],"install":[{"cmd":"pip install pytest-json","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required testing framework, version 2.7 or newer. Note that compatibility with recent pytest versions is not guaranteed due to the plugin's age.","package":"pytest","optional":false}],"imports":[{"note":"pytest-json is a plugin and is activated via command-line flags, not direct imports for basic usage.","symbol":"pytest","correct":"import pytest"}],"quickstart":{"code":"import pytest\nimport json\nimport os\n\n# Create a dummy test file for demonstration (test_example.py)\nwith open('test_example.py', 'w') as f:\n    f.write(\"\"\"\ndef test_success():\n    assert True\n\ndef test_failure():\n    assert False\n\"\"\")\n\n# Define the output report path\nreport_path = 'report.json'\n\n# Run pytest with the json report plugin\n# Ensure pytest-json is installed in the environment\n# The exit code can be non-zero if tests fail, so we capture it.\nexit_code = pytest.main([f'--json={report_path}', 'test_example.py'])\n\n# Check if the report was generated and read it\nif os.path.exists(report_path):\n    with open(report_path, 'r') as f:\n        report_data = json.load(f)\n    print(f\"JSON report generated successfully:\\n{json.dumps(report_data, indent=2)}\")\n    os.remove(report_path)\n    os.remove('test_example.py')\nelse:\n    print(\"JSON report was not generated.\")\n\n# Example of custom environment data (requires conftest.py)\n# conftest.py content:\n# @pytest.fixture(scope='session', autouse=True):\n# def extra_json_environment(request):\n#     request.config._json_environment.append(('CI_BUILD_ID', os.environ.get('CI_BUILD_ID', 'local')))\n","lang":"python","description":"To use `pytest-json`, create a test file (e.g., `test_example.py`). Then, run `pytest` from your terminal with the `--json` flag, specifying the desired output file. The plugin will generate a JSON report containing the test results. Custom environment data can be added via a `pytest` fixture in `conftest.py`."},"warnings":[{"fix":"Consider using 'pytest-json-report' (numirias/pytest-json-report) which is actively maintained and supports modern Python and pytest versions, or pin your Python and pytest versions to those supported by pytest-json if legacy compatibility is critical.","message":"pytest-json has not been updated since January 2016 and officially supports Python versions 2.7, 3.3, 3.4, and 3.5, and py.test 2.7 or newer. It is highly likely to be incompatible with modern Python (>=3.6) and recent pytest versions due to significant changes in both Python and pytest's internal APIs and hook specifications.","severity":"breaking","affected_versions":"All versions of pytest-json with Python >=3.6 or pytest >=3.0 (approx.)"},{"fix":"For advanced customization, consult the pytest changelog for changes to internal structures or consider using a more modern JSON reporting plugin that provides stable extension points.","message":"The plugin relies on internal pytest structures for customization (e.g., `request.config._json_environment` and `report.stage_metadata`). These internal APIs are not part of pytest's public, stable interface and are subject to change without warning in newer pytest releases, leading to `AttributeError` or other unexpected behavior.","severity":"gotcha","affected_versions":"pytest versions newer than ~2.x or 3.x when pytest-json was last updated."},{"fix":"Evaluate migrating to 'pytest-json-report' or another actively maintained pytest plugin that offers JSON reporting capabilities.","message":"pytest-json is no longer actively maintained. This means it will not receive new features, bug fixes, or security updates. Using an unmaintained library can introduce vulnerabilities or become a blocker for upgrading other dependencies.","severity":"deprecated","affected_versions":"All versions (0.1.2 to 0.4.0)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure you are running `pytest` with the `--json` flag (e.g., `pytest --json=report.json`). If the error persists, it indicates an incompatibility with your `pytest` version. Downgrade `pytest` to a version compatible with `pytest-json` (e.g., `pytest<3.0` for Python 3.5, even older for Python 2.7).","cause":"This error typically occurs when attempting to access `session.config._json_report` in a `pytest` hook or fixture when the `pytest-json` plugin was not loaded or its internal configuration attribute has changed in a newer `pytest` version.","error":"AttributeError: 'Config' object has no attribute '_json_report'"},{"fix":"Verify that all custom data added to the report is valid JSON, ensuring strings are double-quoted and complex Python objects are converted to their JSON-serializable equivalents (e.g., dictionaries, lists, strings, numbers, booleans, null).","cause":"This is a general JSON parsing error, but when encountered with `pytest-json` reports, it often means that custom metadata added via `report.stage_metadata` or `request.config._json_environment` in `conftest.py` is not strictly JSON-serializable (e.g., Python objects, single-quoted strings, or unescaped characters).","error":"json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line X column Y (char Z)"}]}