Pytest plugin to generate json report in CTRF (Common Test Report Format)
Project description
CTRF for pytest
Pytest implementation of Common Test Report Format (CTRF) for test results.
Test report will be generated in JSON format.
Test report can be used to prettify the report in GitHub Actions with github-actions-ctrf.
Do not worry if report in GitHub does not appear immediately. It takes some time to process the report.
Features
- Generates JSON report
- Tested to work correctly with and without pytest-xdist
- Tested to get browser name from pytest-playwright
- Parametrized tests are supported and reported as 1 test with multiple retries
Installation
pip install pytest-json-ctrf
Usage
generate report.json file in the root directory of the project. File path is mandatory
pytest --ctrf report.json
Environment Variables may be used to specify the required Environment Object fields when using the CTRF slack-test-reporter.
CTRF_BUILD_NAME="Pytest JSON CTRF Report"
CTRF_BUILD_NUMBER="000"
CTRF_BUILD_URL="https://ctrf.io]"
JSON example
More info here: https://ctrf.io/docs/schema/examples
{
"results": {
"tool": {
"name": "jest"
},
"summary": {
"tests": 3,
"passed": 1,
"failed": 1,
"pending": 0,
"skipped": 1,
"other": 0,
"start": 1706644023,
"stop": 1706644043
},
"environment": {
"buildName": "Pytest JSON CTRF Report",
"buildNumber": "000",
"buildUrl": "https://ctrf.io"
},
"tests": [
{
"name": "User should be able to login",
"status": "passed",
"duration": 1200
},
{
"name": "User profile information should be correct",
"status": "failed",
"duration": 800
},
{
"name": "User should be able to logout",
"status": "skipped",
"duration": 0
}
]
}
}
Report Example
Technical details
For future me and others who are interested in the technical details of the implementation.
The main idea is to handle xdist plugin because without it collecting report is quite straightforward.
By the example of putest-json-report plugin, I have learned that different plugins can be registered for the controller and workers node.
The pytest_runtest_logreport hook in the controller node is used to collect the test results from all the nodes so other nodes can just add some details to the TestReport object.
Credits
- https://ctrf.io/ -> nice data format
- https://github.com/numirias/pytest-json-report -> Source of inspiration and dealing with xdist sync
- https://github.com/testomatio/pytestomatio -> Source of inspiration for creating pytest plugins
- https://github.com/infopulse/Playwright-course-python -> The report will be used in the demo project as +1 report option
Roadmap
- Add screenshots handling
- Add hooks for the report extension
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_json_ctrf-0.4.1.tar.gz.
File metadata
- Download URL: pytest_json_ctrf-0.4.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c37db76c0aaf5d5eb38156cc8e4c95389238082167eee34fa7a49c6777dd9fbb
|
|
| MD5 |
732a30ed61f63fc8640fd59163a783e3
|
|
| BLAKE2b-256 |
ec97dfa0e900466eba3bf58aa766a93e316acc0eb7e64e2676a1b47238597fd1
|
Provenance
The following attestation bundles were made for pytest_json_ctrf-0.4.1.tar.gz:
Publisher:
deploy.yml on qamania/pytest-common-test-report-json
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_json_ctrf-0.4.1.tar.gz -
Subject digest:
c37db76c0aaf5d5eb38156cc8e4c95389238082167eee34fa7a49c6777dd9fbb - Sigstore transparency entry: 1202889174
- Sigstore integration time:
-
Permalink:
qamania/pytest-common-test-report-json@8e8529c4b8d5e6d5e28e41244994f47a91f3e419 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/qamania
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@8e8529c4b8d5e6d5e28e41244994f47a91f3e419 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_json_ctrf-0.4.1-py3-none-any.whl.
File metadata
- Download URL: pytest_json_ctrf-0.4.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eee44de3913672fe25243e884466530528f0295352c4ca65ec8e14924785048c
|
|
| MD5 |
308c604959c4e8e249742e07aeb11bb6
|
|
| BLAKE2b-256 |
3303ba1c6b9039b079393fff5846555c48c66edf3ac34a9368b54cc2b6a5cddf
|
Provenance
The following attestation bundles were made for pytest_json_ctrf-0.4.1-py3-none-any.whl:
Publisher:
deploy.yml on qamania/pytest-common-test-report-json
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_json_ctrf-0.4.1-py3-none-any.whl -
Subject digest:
eee44de3913672fe25243e884466530528f0295352c4ca65ec8e14924785048c - Sigstore transparency entry: 1202889176
- Sigstore integration time:
-
Permalink:
qamania/pytest-common-test-report-json@8e8529c4b8d5e6d5e28e41244994f47a91f3e419 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/qamania
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@8e8529c4b8d5e6d5e28e41244994f47a91f3e419 -
Trigger Event:
push
-
Statement type: