pytest-report-stream


Namepytest-report-stream JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/kolitiri/pytest-report-stream
SummaryA pytest plugin which allows to stream test reports at runtime
upload_time2023-10-22 18:09:23
maintainerChristos Liontos
docs_urlNone
authorChristos Liontos
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. -*- mode: rst; coding: utf-8 -*-

============================================================
pytest-report-stream - Live stream test reports
============================================================

.. image:: https://img.shields.io/pypi/v/pytest-report-stream.svg
    :target: https://pypi.org/project/pytest-report-stream
    :alt: PyPI version

.. image:: https://img.shields.io/pypi/pyversions/pytest-report-stream.svg
    :target: https://pypi.org/project/pytest-report-stream
    :alt: Python versions


:Authors: Christos Liontos
:Version: 0.1.0
:Date:    2023-09-22
:Download: https://pypi.python.org/pypi/pytest-report-stream#downloads
:Code: https://github.com/kolitiri/pytest-report-stream


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 <https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.hookspec.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:

.. code-block:: python3

    {
        "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.

.. code-block:: sh

    pip install pytest-report-stream


Usage
============================================================
The plugin is available after installation and can be enabled using the ``--stream-reports`` flag.

.. code-block:: sh

    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
------------------------------------------------------------

.. code-block:: python3

    # content of tests/test_my_module.py
    def test_sync():
        pass

Aynchronous test using the default STDOUT report client
------------------------------------------------------------

.. code-block:: python3

    # content of tests/test_my_module.py
    import pytest

    @pytest.mark.asyncio
    async def test_async():
        pass

Aynchronous test using a custom report client
------------------------------------------------------------

.. code-block:: python3

    # 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)

.. code-block:: python3

    # 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 <https://tox.wiki/en>`_, please ensure
the coverage at least stays the same before you submit a pull request.

.. code-block:: sh

    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 <https://github.com/kolitiri/pytest-report-stream/issues>`_ along with a detailed description.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kolitiri/pytest-report-stream",
    "name": "pytest-report-stream",
    "maintainer": "Christos Liontos",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "christos.liontos.pr@gmail.com",
    "keywords": "",
    "author": "Christos Liontos",
    "author_email": "christos.liontos.pr@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/70/e5/a2a99f4d51b605a6234907b81ccac1f235f3e82797d53eba72037223c805/pytest-report-stream-0.1.0.tar.gz",
    "platform": null,
    "description": ".. -*- mode: rst; coding: utf-8 -*-\n\n============================================================\npytest-report-stream - Live stream test reports\n============================================================\n\n.. image:: https://img.shields.io/pypi/v/pytest-report-stream.svg\n    :target: https://pypi.org/project/pytest-report-stream\n    :alt: PyPI version\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-report-stream.svg\n    :target: https://pypi.org/project/pytest-report-stream\n    :alt: Python versions\n\n\n:Authors: Christos Liontos\n:Version: 0.1.0\n:Date:    2023-09-22\n:Download: https://pypi.python.org/pypi/pytest-report-stream#downloads\n:Code: https://github.com/kolitiri/pytest-report-stream\n\n\nWelcome to pytest-report-stream!\n============================================================\npytest-report-stream is a pytest plugin which allows to stream test reports at runtime.\n\nIt is a simple plugin the leverages pytest's build-in hook `pytest_runtest_makereport <https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.hookspec.pytest_runtest_makereport>`_ to intercept test execution and publish the status of the test run.\n\nThe plugin produces report events at specific moments:\n- One report in the beginning of the test run\n- One report in the end of each test\n- One report in the end of the test run\n\nThe report structure looks like the dictionary below:\n\n.. code-block:: python3\n\n    {\n        \"test_run_tag\": \"My first test framework\",\n        \"test_run_id\": \"5e080accaee748dc80619ee99245124e\",\n        \"timestamps\": {\n            \"started\": datetime.datetime(2023, 10, 22, 17, 4, 43, 161646),\n            \"duration\": 0.002042,\n            \"finished\": datetime.datetime(2023, 10, 22, 17, 4, 43, 163688),\n        },\n        \"summary\": {\"passed\": 1, \"failed\": 1, \"status\": \"in-progress\"},\n        \"results\": {\n            \"tests/test_module1\": {\n                \"test_func_1\": {\n                    \"name\": \"test_func_1\",\n                    \"description\": \"Docstrings of function 1\",\n                    \"status\": \"passed\",\n                    \"error\": \"None\",\n                },\n                \"test_func_2\": {\n                    \"name\": \"test_func_2\",\n                    \"description\": \"Docstrings of function 2\",\n                    \"status\": \"failed\",\n                    \"error\": \"None\",\n                }\n            }\n        },\n    }\n\nUse cases\n------------------------------------------------------------\nThe ``pytest-report-stream`` plugin can be particularly useful while running large and long lasting integration testing suites using pytest.\n\nThe plugin can be used to stream live report events to a remote service, allowing to monitor the progress and the status of the tests.\n\nFor example, Jenkins and other CI/CD tools are great, but there might be a requirement to aggregate test results from multiple builds.\n\n\nInstallation\n============================================================\nInstall the plugin as below.\n\n.. code-block:: sh\n\n    pip install pytest-report-stream\n\n\nUsage\n============================================================\nThe plugin is available after installation and can be enabled using the ``--stream-reports`` flag.\n\n.. code-block:: sh\n\n    pytest --stream-reports\n\nThe plugin is using a ``report_client: ReportClient`` instance to generate the reports.\n\nA 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``)\n\nThe default client can be overriden in your own ``pytest_configure`` with an implementation of the abstract ``pytest_report_stream::ReportClient`` class.\n\nSynchronous test using the default STDOUT report client\n------------------------------------------------------------\n\n.. code-block:: python3\n\n    # content of tests/test_my_module.py\n    def test_sync():\n        pass\n\nAynchronous test using the default STDOUT report client\n------------------------------------------------------------\n\n.. code-block:: python3\n\n    # content of tests/test_my_module.py\n    import pytest\n\n    @pytest.mark.asyncio\n    async def test_async():\n        pass\n\nAynchronous test using a custom report client\n------------------------------------------------------------\n\n.. code-block:: python3\n\n    # content of tests/conftest.py\n    import pytest\n    from pytest_report_stream import ReportClient, ReportStreamPlugin\n\n\n    class myCustomReportClient(ReportClient):\n        async def publish_report(self, report_msg: dict) -> None:\n            print('Some log comming from my custom report client')\n\n\n    def pytest_configure(config):\n        if config.option.stream_reports:\n            config._stream_reports = ReportStreamPlugin(\n                report_client=myCustomReportClient()\n            )\n            config.pluginmanager.register(config._stream_reports)\n\n.. code-block:: python3\n\n    # content of tests/test_my_module.py\n    import pytest\n\n    @pytest.mark.asyncio\n    async def test_async():\n        pass\n\nYou can implement the ``publish_report`` function and do pretty much anything, such as publishing the events to a message broker.\n\n\nRequirements\n============================================================\n* pytest>=7.0.0\n* pytest-asyncio\n\n\nContributing\n============================================================\nContributions are very welcome.\n\nTests can be run with `tox <https://tox.wiki/en>`_, please ensure\nthe coverage at least stays the same before you submit a pull request.\n\n.. code-block:: sh\n\n    tox\n\n\nLicense\n============================================================\nDistributed under the terms of the MIT license, \"pytest-report-stream\" is free and open source software\n\n\nIssues\n============================================================\nIf you encounter any problems, please `file an issue <https://github.com/kolitiri/pytest-report-stream/issues>`_ along with a detailed description.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A pytest plugin which allows to stream test reports at runtime",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/kolitiri/pytest-report-stream"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "70e5a2a99f4d51b605a6234907b81ccac1f235f3e82797d53eba72037223c805",
                "md5": "ef803df16e579dbffd7e80430182ce82",
                "sha256": "b1bd187eb8b21f6da7b59eab17dcd11de4e69fe10b1d6fcf0d3ec135b2184ddd"
            },
            "downloads": -1,
            "filename": "pytest-report-stream-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ef803df16e579dbffd7e80430182ce82",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 6598,
            "upload_time": "2023-10-22T18:09:23",
            "upload_time_iso_8601": "2023-10-22T18:09:23.297894Z",
            "url": "https://files.pythonhosted.org/packages/70/e5/a2a99f4d51b605a6234907b81ccac1f235f3e82797d53eba72037223c805/pytest-report-stream-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-22 18:09:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kolitiri",
    "github_project": "pytest-report-stream",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "pytest-report-stream"
}
        
Elapsed time: 0.17349s