Package: pytest-report-stream
Authors:Christos LiontosVersion:0.1.0Date:2023-09-22Download:https://pypi.python.org/pypi/pytest-report-stream#downloadsCode:https://github.com/kolitiri/pytest-report-streamWelcome 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 hookpytest_runtest_makereportto 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 runThe 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 casesThepytest-report-streamplugin 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.InstallationInstall the plugin as below.pipinstallpytest-report-streamUsageThe plugin is available after installation and can be enabled using the--stream-reportsflag.pytest--stream-reportsThe plugin is using areport_client: ReportClientinstance 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 runpytestwith the flag-s)The default client can be overriden in your ownpytest_configurewith an implementation of the abstractpytest_report_stream::ReportClientclass.Synchronous test using the default STDOUT report client# content of tests/test_my_module.pydeftest_sync():passAynchronous test using the default STDOUT report client# content of tests/test_my_module.pyimportpytest@pytest.mark.asyncioasyncdeftest_async():passAynchronous test using a custom report client# content of tests/conftest.pyimportpytestfrompytest_report_streamimportReportClient,ReportStreamPluginclassmyCustomReportClient(ReportClient):asyncdefpublish_report(self,report_msg:dict)->None:print('Some log comming from my custom report client')defpytest_configure(config):ifconfig.option.stream_reports:config._stream_reports=ReportStreamPlugin(report_client=myCustomReportClient())config.pluginmanager.register(config._stream_reports)# content of tests/test_my_module.pyimportpytest@pytest.mark.asyncioasyncdeftest_async():passYou can implement thepublish_reportfunction and do pretty much anything, such as publishing the events to a message broker.Requirementspytest>=7.0.0pytest-asyncioContributingContributions are very welcome.Tests can be run withtox, please ensure
the coverage at least stays the same before you submit a pull request.toxLicenseDistributed under the terms of the MIT license, “pytest-report-stream” is free and open source softwareIssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.