Registry / testing / pytest-json

pytest-json

JSON →
library0.4.0pypypi✓ verified 87d ago

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.

pip install pytest-json
INSTALL
IMPORT
SIG · PYTEST-JSON
P
pytest-json
testingpythonv0.4.0
Install
3.5s avg
Import
398ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.421s · 32.1MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.5s · import 0.376s · 33MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest
import pytest
pytest-json is a plugin and is activated via command-line flags, not direct imports for basic usage.

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`.

import pytest import json import os # Create a dummy test file for demonstration (test_example.py) with open('test_example.py', 'w') as f: f.write(""" def test_success(): assert True def test_failure(): assert False """) # Define the output report path report_path = 'report.json' # Run pytest with the json report plugin # Ensure pytest-json is installed in the environment # The exit code can be non-zero if tests fail, so we capture it. exit_code = pytest.main([f'--json={report_path}', 'test_example.py']) # Check if the report was generated and read it if os.path.exists(report_path): with open(report_path, 'r') as f: report_data = json.load(f) print(f"JSON report generated successfully:\n{json.dumps(report_data, indent=2)}") os.remove(report_path) os.remove('test_example.py') else: print("JSON report was not generated.") # Example of custom environment data (requires conftest.py) # conftest.py content: # @pytest.fixture(scope='session', autouse=True): # def extra_json_environment(request): # request.config._json_environment.append(('CI_BUILD_ID', os.environ.get('CI_BUILD_ID', 'local')))
Debug
Known issues
breakingpytest-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.
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.
affects: All versions of pytest-json with Python >=3.6 or pytest >=3.0 (approx.)
gotchaThe 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.
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.
affects: pytest versions newer than ~2.x or 3.x when pytest-json was last updated.
deprecatedpytest-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.
fix
Evaluate migrating to 'pytest-json-report' or another actively maintained pytest plugin that offers JSON reporting capabilities.
affects: All versions (0.1.2 to 0.4.0)
Errors
Common errors & fixes
AttributeError: 'Config' object has no attribute '_json_report'
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.
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).
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line X column Y (char Z)
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).
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).
Upgrade
Version history
0.4.0latest on PyPI · released Jan 18, 2016
Audit
Dependencies
pytestrequiredRequired testing framework, version 2.7 or newer. Note that compatibility with recent pytest versions is not guaranteed due to the plugin's age.
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
pytest-json — pip install pytest-json · libregistry