Pytest plugin to record discovered tests in a file
Project description
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-report
together with--collect-only
option to collect tests and generate a JSON file:
pytest --collect-only --collect-report=collect.json
- Use the
--collect-log
together with--collect-only
option 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:
SessionStart
JSON SchemaWarningMessage
JSON SchemaErrorMessage
JSON SchemaCollectReport
JSON SchemaSessionFinish
JSON Schema
Python tools can also use the DiscoveryEvent
dataclass to parse the JSON lines file, as well as the differnt event classes:
SessionStart
dataclassWarningMessage
dataclassErrorMessage
dataclassCollectReport
dataclassSessionFinish
dataclassTestItem
dataclass
Note: The code generation task is automated using
rye run generate-models
project 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-log
plugin. - pytest-csv: The
pytest-csv
plugin 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
.
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
Hashes for pytest_discover-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 669377e22684e13547600e9bba980318fda231217b50b58e82f376d1e458148a |
|
MD5 | 7d8bf0b3ee8b16f63e66558c194593c6 |
|
BLAKE2b-256 | b4c75a63c2fe08910eb518574e63574ec71c54f150642d9a4550950ca1966418 |