pytest-discover
A plugin to write pytest collect output to either a JSON file or a JSON lines file.
Install
pip install pytest-discover
Usage
- Use the
--collect-reporttogether with--collect-onlyoption to collect tests and generate a JSON file:
pytest --collect-only --collect-report=collect.json
- Use the
--collect-logtogether with--collect-onlyoption to collect tests and generate a JSON lines file:
pytest --collect-only --collect-log=collect.jsonl
Produced JSON output
The JSON file generated by --collect-report option follows the DiscoveryResult JSON Schema.
Python tools can also use the DiscoveryResult dataclass to parse the JSON file.
Produced JSON Lines output
The JSON lines file generated by --collect-log option contains one JSON object per line. Each line is a JSON object that follows the DiscoveryEvent JSON Schema.
This schema is the union of the different events that can be emitted by the discovery process:
SessionStartJSON SchemaWarningMessageJSON SchemaErrorMessageJSON SchemaCollectReportJSON SchemaSessionFinishJSON Schema
Python tools can also use the DiscoveryEvent dataclass to parse the JSON lines file, as well as the differnt event classes:
SessionStartdataclassWarningMessagedataclassErrorMessagedataclassCollectReportdataclassSessionFinishdataclassTestItemdataclass
Note: The code generation task is automated using
rye run generate-modelsproject script.
Alternatives
- pytest-json-report: This plugin not only generates a JSON report with collected nodes, but also with test results. It is a more complete solution than
pytest-discover. However, there is no JSON schema to validate the output, nor JSON lines output.
Credits
- pytest-report-log: This package was heavily inspired by the
report-logplugin. - pytest-csv: The
pytest-csvplugin was also a source of inspiration. datamodel-code-generator: The dataclasses generation from JSON schemas is performed usingdatamodel-code-generator.- rye: Project management is easy thanks to
rye.
Release files for pytest-discover 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_discover-0.4.0.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_discover-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.7 kB
Release files / pytest_discover-0.4.0.tar.gz
| Download URL | pytest_discover-0.4.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c825332b82a64159bdec62f9b9afa6ba8bf7cbbc886aa5397d797db4195ecf17
|
|
BLAKE2b-256 checksum How to use checksums |
5a5725f6c97cfe5eb6e4aea2bb4be88edb4af0306b23cca7f2d85745f8d13db8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.2
|
Release files / pytest_discover-0.4.0-py3-none-any.whl
| Download URL | pytest_discover-0.4.0-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3332b241ae21b5bbfe1edafc8d40d1c759a111b1c1636ef2bc050ac5e2e0e519
|
|
BLAKE2b-256 checksum How to use checksums |
cdbc791173f87cc2c1dbc0105258585d3074e392c153b51449490d3023e8975b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.2
|