pytest-report-stream - Live stream test reports
- Authors:
Christos Liontos
- Version:
0.1.0
- Date:
2023-09-22
- Download:
- Code:
Welcome to pytest-report-stream!
pytest-report-stream is a pytest plugin which allows to stream test reports at runtime.
It is a simple plugin the leverages pytest’s build-in hook pytest_runtest_makereport to intercept test execution and publish the status of the test run.
The plugin produces report events at specific moments: - One report in the beginning of the test run - One report in the end of each test - One report in the end of the test run
The report structure looks like the dictionary below:
{
"test_run_tag": "My first test framework",
"test_run_id": "5e080accaee748dc80619ee99245124e",
"timestamps": {
"started": datetime.datetime(2023, 10, 22, 17, 4, 43, 161646),
"duration": 0.002042,
"finished": datetime.datetime(2023, 10, 22, 17, 4, 43, 163688),
},
"summary": {"passed": 1, "failed": 1, "status": "in-progress"},
"results": {
"tests/test_module1": {
"test_func_1": {
"name": "test_func_1",
"description": "Docstrings of function 1",
"status": "passed",
"error": "None",
},
"test_func_2": {
"name": "test_func_2",
"description": "Docstrings of function 2",
"status": "failed",
"error": "None",
}
}
},
}
Use cases
The pytest-report-stream plugin can be particularly useful while running large and long lasting integration testing suites using pytest.
The plugin can be used to stream live report events to a remote service, allowing to monitor the progress and the status of the tests.
For example, Jenkins and other CI/CD tools are great, but there might be a requirement to aggregate test results from multiple builds.
Installation
Install the plugin as below.
pip install pytest-report-stream
Usage
The plugin is available after installation and can be enabled using the --stream-reports flag.
pytest --stream-reports
The plugin is using a report_client: ReportClient instance to generate the reports.
A default report_client is used to log the reports in STDOUT. (Note that in order to view the reports in STDOUT you will need to run pytest with the flag -s)
The default client can be overriden in your own pytest_configure with an implementation of the abstract pytest_report_stream::ReportClient class.
Synchronous test using the default STDOUT report client
# content of tests/test_my_module.py
def test_sync():
pass
Aynchronous test using the default STDOUT report client
# content of tests/test_my_module.py
import pytest
@pytest.mark.asyncio
async def test_async():
pass
Aynchronous test using a custom report client
# content of tests/conftest.py
import pytest
from pytest_report_stream import ReportClient, ReportStreamPlugin
class myCustomReportClient(ReportClient):
async def publish_report(self, report_msg: dict) -> None:
print('Some log comming from my custom report client')
def pytest_configure(config):
if config.option.stream_reports:
config._stream_reports = ReportStreamPlugin(
report_client=myCustomReportClient()
)
config.pluginmanager.register(config._stream_reports)
# content of tests/test_my_module.py
import pytest
@pytest.mark.asyncio
async def test_async():
pass
You can implement the publish_report function and do pretty much anything, such as publishing the events to a message broker.
Requirements
pytest>=7.0.0
pytest-asyncio
Contributing
Contributions are very welcome.
Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
tox
License
Distributed under the terms of the MIT license, “pytest-report-stream” is free and open source software
Issues
If you encounter any problems, please file an issue along with a detailed description.
Metadata
Release files for pytest-report-stream 0.1.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 | Provenance | Actions |
|---|---|---|---|---|
| pytest-report-stream-0.1.0.tar.gz | 6.6 kB | Without provenance | Details for pytest-report-stream-0.1.0.tar.gz |
Release files / pytest-report-stream-0.1.0.tar.gz
| Download URL | pytest-report-stream-0.1.0.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1bd187eb8b21f6da7b59eab17dcd11de4e69fe10b1d6fcf0d3ec135b2184ddd
|
|
BLAKE2b-256 checksum How to use checksums |
70e5a2a99f4d51b605a6234907b81ccac1f235f3e82797d53eba72037223c805
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Security for pytest-report-stream 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.