Registry / testing / pytest-json-ctrf

pytest-json-ctrf

JSON →
library0.3.6pypypiunverified

pytest-json-ctrf is a pytest plugin that generates test reports in the Common Test Report Format (CTRF) as a JSON file. This standard format allows for consistent reporting across various testing tools and frameworks, facilitating better analysis and integration with external systems like GitHub Actions for prettifying reports. The current version is 0.3.6, with releases tied to pytest compatibility and feature enhancements.

pip install pytest-json-ctrf
INSTALL
IMPORT
SIG · PYTEST-JSON-CTRF
P
pytest-json-ctrf
testingpythonv0.3.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

First, create a simple test file (e.g., `test_example.py`). Then, run pytest from your terminal, specifying the `--ctrf` flag followed by the desired output filename. This will generate a JSON report in the Common Test Report Format in the specified file.

import pytest # tests/test_example.py def test_passing_example(): assert True def test_failing_example(): assert False # To run and generate report: # pytest --ctrf report.json # cat report.json
Debug
Known issues
gotchaThe `--ctrf` command-line option requires a file path argument. If not provided, pytest will not generate the CTRF report, or may raise an error depending on the pytest version. Ensure a valid file path is always specified.
fix
Always use `pytest --ctrf <your_report_file_name.json>`.
affects: All versions
gotchaAs a pytest plugin, `pytest-json-ctrf` is activated via a command-line option (`--ctrf`) rather than direct Python imports within your test code. Attempting to import symbols directly from `pytest_json_ctrf` in your tests is generally unnecessary and will likely result in an `ImportError` or other unexpected behavior.
fix
Ensure the plugin is installed (`pip install pytest-json-ctrf`) and activate it using the `--ctrf` command-line flag when running pytest. No explicit Python imports are typically needed in your test files for this plugin.
affects: All versions
gotchaTo ensure your tests are discovered and reported correctly by pytest (and subsequently by `pytest-json-ctrf`), adhere to pytest's standard test discovery rules: test files should start with `test_` or end with `_test.py`, and test functions/methods should start with `test_`.
fix
Rename test files and functions to follow pytest conventions (e.g., `test_my_feature.py`, `def test_functionality()`).
affects: All versions
Errors
Common errors & fixes
pytest: error: unrecognized arguments: --json-ctrf=report.json
This error indicates that the `pytest-json-ctrf` plugin is either not installed or not accessible in the current Python environment where pytest is being executed, preventing pytest from recognizing its command-line option.
fix
Ensure the plugin is installed by running `pip install pytest-json-ctrf` in the active Python environment. If already installed, verify the environment's `PATH` or virtual environment activation.
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
This error occurs when attempting to parse the generated CTRF report file (e.g., `report.json`), but the file is empty or contains malformed, non-JSON content.
fix
Verify that your pytest tests are actually running and producing reportable outcomes; an empty file often indicates no tests were executed or reported, or a prior error prevented report generation.
FileNotFoundError: [Errno 2] No such file or directory: 'report.json'
This error occurs when a subsequent command or script tries to access the CTRF report file, but it was either not generated, or not created in the expected directory.
fix
Confirm the `pytest --json-ctrf=report.json` command was executed successfully without errors, and check the current working directory or specified path to ensure the `report.json` file exists in the expected location after the test run.
PermissionError: [Errno 13] Permission denied: 'report.json'
Pytest-json-ctrf is attempting to create or write the report file in a directory where the running user or process does not have sufficient write permissions.
fix
Change the output directory to a location where the user has write permissions (e.g., the current working directory or a user-specific temporary directory), or adjust the file system permissions for the target directory.
Upgrade
Version history
0.3.6latest on PyPI · released Dec 28, 2025
Audit
Dependencies
pytestrequiredCore testing framework for which this is a plugin.
Agent activity
95 hits · last 30 days
node
86
OpenAI (training)
1
Resources
pytest-json-ctrf — pip install pytest-json-ctrf · libregistry