Registry / testing / pytest-json-report

pytest-json-report

JSON →
library1.5.0pypypiunverified

pytest-json-report is a pytest plugin that generates a comprehensive JSON report of your test results. It provides detailed information on test outcomes, collected items, and environment details, useful for integration with CI/CD systems or custom reporting tools. The current version is 1.5.0, with minor releases occurring every few months to address bugs and add features.

pip install pytest-json-report
INSTALL
IMPORT
SIG · PYTEST-JSON-REPORT
P
pytest-json-report
testingpythonv1.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Create a `test_example.py` file with some tests, then run `pytest --json-report` from your terminal. This command will execute your tests and generate a `report.json` file in your current working directory containing the test results and a summary.

import pytest import json import os def test_success(): assert True def test_failure(): assert False @pytest.mark.skip(reason="demonstrating skip") def test_skipped(): pass def test_record_property(record_property): record_property("my_custom_key", "my_custom_value") assert True # Run pytest and generate report.json # os.system('pytest --json-report') would run it, but for a quickstart example, we'll demonstrate the command. print("To run this example, save it as `test_example.py` and run:") print("pytest --json-report") print("Then inspect the generated `report.json` file.") # Example of reading the report (would typically be in a separate script or CI/CD) # if os.path.exists('report.json'): # with open('report.json', 'r') as f: # report_data = json.load(f) # print(json.dumps(report_data['summary'], indent=2))
Debug
Known issues
breakingPython 2.x support was dropped in v1.2.4. Python 3.7+ is now required. As of v1.5.0, supported Python versions are 3.7 - 3.10, and pytest versions 3.7 - 7.0.
fix
Ensure your project uses Python 3.7-3.10 and pytest 3.7-7.0 to use pytest-json-report v1.5.0 and newer.
affects: <1.2.4 (for Python 2.x users), <1.5.0 (for users on newer Python/pytest versions not yet officially supported)
gotchaThe plugin does not activate automatically. You must explicitly enable it via the command line with `--json-report` or by adding `addopts = --json-report` to your `pytest.ini` configuration file.
fix
Always include `--json-report` when running pytest or configure it in `pytest.ini`.
affects: All versions
gotchaThe structure and content of the JSON report, particularly the `summary` and `collected` counts, have evolved. Specifically, the `collected` count was fixed in v1.5.0 to accurately reflect all items, and the `deselected` count was added to the summary in v1.5.0 (and to collector result in v1.2.0).
fix
If parsing reports from older versions, be aware that `collected` and `deselected` counts might be missing or inaccurate. Update to v1.5.0 or newer for the most accurate and complete summary data.
affects: <1.5.0
gotchaBy default, the report is saved as `report.json` in the current working directory. To customize the output file path or control terminal verbosity, use specific command-line options.
fix
Use `--json-report-file=/path/to/your/report.json` to specify the output path. Use `--json-report-verbosity=0|1|2` (since v1.4.0) to control terminal output verbosity (0=silent, 1=summary only, 2=verbose).
affects: All versions
Errors
Common errors & fixes
pytest: error: unrecognized arguments: --json-report
The pytest-json-report plugin is either not installed, or pytest is unable to locate and load it.
fix
Install the plugin using pip: `pip install pytest-json-report`
pytest --json-report not generating json file
The `--json-report` flag, when used alone, prints the JSON report to standard output; it does not automatically save it to a file.
fix
Use the `--json-report-file` option to specify an output file: `pytest --json-report --json-report-file=report.json`
pytest: error: argument --json-report-file: expected one argument
The `--json-report-file` option requires a file path to be provided immediately after it.
fix
Specify a file name for the report: `pytest --json-report --json-report-file=output.json`
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The generated JSON report file is empty, truncated, or contains non-JSON content at the beginning, preventing a JSON parser from reading it correctly.
fix
Ensure that your tests complete without errors that might corrupt the report file and that no other process or output is inadvertently writing to the specified report file path.
Upgrade
Version history
1.5.0latest on PyPI · released Mar 15, 2022
Audit
Dependencies
pytestrequiredCore testing framework; this library is a plugin for pytest.
Agent activity
1 hits · last 30 days
Resources
pytest-json-report — pip install pytest-json-report · libregistry