pytest-stats


Namepytest-stats JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/amitwer/pytest-stats
SummaryCollects tests metadata for future analysis, easy to extend for any data store
upload_time2024-07-03 04:34:50
maintainerNone
docs_urlNone
authorAmit Wertheimer
requires_python>=3.8
licenseMIT
keywords pytest stats metadata
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pytest-stats
This library is collecting metadata about your test executions, and enables you to send it to a datastore of your liking.

## Architecture
The library is designed in a hexagonal architecture in mind - separating data collection and reporting.
There are two main parts to the code - metadata collection and reporting. the collection engine stores the metadata in pytest's stash (for session and for test) and uses pytest built-in hooks in order to populate the data and trigger the reporting. 
The reporting part is allowing reporters to register, then delegates the actual work to the registered reporters, enabling easy customization. 

## Implementation guide
In order to include pytest-stats capabilities in your code, all you need to do is to install the package `pip install pytest-stats`.  
However, this will only provide you with a text report provided by the built-in DefaultTextReporter.
In order to store the data in your own DB you'll need to:  
1. Create a new reporter (inherit the abstract `ResultsReporter` class)
2. Register an instance of your reporter using the provided new hook `pytest_stats_register_reporters`.<br>Example: 
```
@pytest.hookimpl()
def pytest_stats_register_reporters(reporters:'ReportersRegistry'):
    reporters.register(MyReporter())
```

## Implementation details
### how is data collected and reported?
Most data is collected by hooking the following pytest-provided hooks:
* `pytest_sessionstart`
* `pytest_sessionfinish`
* `pytest_runtest_protocol`
* `pytest_runtest_makereport`
* `pytest_exception_interact`
### New hooks available
* `pytest_stats_register_reporters`: used to register a new reporter. More than one reporter can be registered at the same hook. <br> Invoked as part of `pytest_configure`
* `pytest_stats_env_data`: Enables adding custom environment information to the session data. <br> Invoked as part of `pytest_sessionstart`

### Utility functions
* `get_test_session_data(session: 'Session') -> TestSessionData` - can be used to fetch the session data in an arbitrary location
* `get_test_item_data(item: 'Item') -> TestItemData` - can be used to fetch the current test data in arbitrary location. For instance, one can call `get_test_item_data(item=request.node).foo="bar"`
* 
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/amitwer/pytest-stats",
    "name": "pytest-stats",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "pytest, stats, metadata",
    "author": "Amit Wertheimer",
    "author_email": "12250123+amitwer@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/a8/81/171369a39c0f5ba029b35ec58013804fe89605875e35e8acc6b23eb7a127/pytest_stats-1.0.0.tar.gz",
    "platform": null,
    "description": "# Pytest-stats\nThis library is collecting metadata about your test executions, and enables you to send it to a datastore of your liking.\n\n## Architecture\nThe library is designed in a hexagonal architecture in mind - separating data collection and reporting.\nThere are two main parts to the code - metadata collection and reporting. the collection engine stores the metadata in pytest's stash (for session and for test) and uses pytest built-in hooks in order to populate the data and trigger the reporting. \nThe reporting part is allowing reporters to register, then delegates the actual work to the registered reporters, enabling easy customization. \n\n## Implementation guide\nIn order to include pytest-stats capabilities in your code, all you need to do is to install the package `pip install pytest-stats`.  \nHowever, this will only provide you with a text report provided by the built-in DefaultTextReporter.\nIn order to store the data in your own DB you'll need to:  \n1. Create a new reporter (inherit the abstract `ResultsReporter` class)\n2. Register an instance of your reporter using the provided new hook `pytest_stats_register_reporters`.<br>Example: \n```\n@pytest.hookimpl()\ndef pytest_stats_register_reporters(reporters:'ReportersRegistry'):\n    reporters.register(MyReporter())\n```\n\n## Implementation details\n### how is data collected and reported?\nMost data is collected by hooking the following pytest-provided hooks:\n* `pytest_sessionstart`\n* `pytest_sessionfinish`\n* `pytest_runtest_protocol`\n* `pytest_runtest_makereport`\n* `pytest_exception_interact`\n### New hooks available\n* `pytest_stats_register_reporters`: used to register a new reporter. More than one reporter can be registered at the same hook. <br> Invoked as part of `pytest_configure`\n* `pytest_stats_env_data`: Enables adding custom environment information to the session data. <br> Invoked as part of `pytest_sessionstart`\n\n### Utility functions\n* `get_test_session_data(session: 'Session') -> TestSessionData` - can be used to fetch the session data in an arbitrary location\n* `get_test_item_data(item: 'Item') -> TestItemData` - can be used to fetch the current test data in arbitrary location. For instance, one can call `get_test_item_data(item=request.node).foo=\"bar\"`\n* ",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Collects tests metadata for future analysis, easy to extend for any data store",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/amitwer/pytest-stats"
    },
    "split_keywords": [
        "pytest",
        " stats",
        " metadata"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8cd78618f39b1de14af968d0af734b94a424a8dc94b073cc06b1081f1f5b730e",
                "md5": "9f4e3a695796341cc0d76f8cdef3cee4",
                "sha256": "5e02c16bcb5fcef075f7ca42a4504a192d1b52e66ca37ae65bdc794e915a3f23"
            },
            "downloads": -1,
            "filename": "pytest_stats-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9f4e3a695796341cc0d76f8cdef3cee4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8326,
            "upload_time": "2024-07-03T04:34:49",
            "upload_time_iso_8601": "2024-07-03T04:34:49.169075Z",
            "url": "https://files.pythonhosted.org/packages/8c/d7/8618f39b1de14af968d0af734b94a424a8dc94b073cc06b1081f1f5b730e/pytest_stats-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a881171369a39c0f5ba029b35ec58013804fe89605875e35e8acc6b23eb7a127",
                "md5": "75e4bae67922283b6d60b37fb3863715",
                "sha256": "373af08da6839623f44a6ed1ee1d06f9314e29fc7a80963d402675914b515b07"
            },
            "downloads": -1,
            "filename": "pytest_stats-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "75e4bae67922283b6d60b37fb3863715",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6840,
            "upload_time": "2024-07-03T04:34:50",
            "upload_time_iso_8601": "2024-07-03T04:34:50.188343Z",
            "url": "https://files.pythonhosted.org/packages/a8/81/171369a39c0f5ba029b35ec58013804fe89605875e35e8acc6b23eb7a127/pytest_stats-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-03 04:34:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "amitwer",
    "github_project": "pytest-stats",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-stats"
}
        
Elapsed time: 1.32978s