Pytest JSON CTRF Reporter
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.
Warnings
- gotcha The `--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.
- gotcha As 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.
- gotcha To 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_`.
Install
-
pip install pytest-json-ctrf
Quickstart
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