Name | pytest-fluentbit JSON |
Version |
0.1.5
JSON |
| download |
home_page | |
Summary | A pytest plugin in order to provide logs via fluentbit |
upload_time | 2023-06-16 22:07:52 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.7 |
license | MIT |
keywords |
pytest
logging
fluent
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pytest-fluent
[![Documentation](https://readthedocs.org/projects/pytest-fluent/badge/?version=latest)](https://pytest-fluent.readthedocs.io/) [![Build Status](https://github.com/Rohde-Schwarz/pytest-fluent/actions/workflows/tests.yml/badge.svg)](https://github.com/Rohde-Schwarz/pytest-fluent/actions/) [![PyPI Versions](https://img.shields.io/pypi/pyversions/pytest-fluent.svg)](https://pypi.python.org/pypi/pytest-fluent) ![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-fluent) [![PyPI Status](https://img.shields.io/pypi/status/pytest-fluent.svg)](https://pypi.python.org/pypi/pytest-fluent) [![PyPI License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
A Python package in order to extend pytest by fluentd logging
## Description
Pytest is one of the most powerful testing suites with a lot of functionality and many plugins. Fluentd is a well-established log collector which is used in many modern web architectures. So, why not putting both worlds together in order to gain real-time log access to your distributed test runs.
pytest-fluent enables you to forward your test data immediately to your prefered log-sink from any node spread around your infrastructure. The streamed data are available for each pytest stage and formatted in JSON.
Each pytest session gets an unique identifier (UID) assigned as well as each executed test case. With these UIDs, you can filter easily for sessions and testcase data entries, for instance in your favorite database.
## Installation
The package is available at pypi.org and can be installed by typing
```shell
pip install pytest-fluentbit
```
## Usage
pytest-fluent-logging forwards meta data from pytest to Fluentd for further processing. The meta data are
* unique session ID
* unique test ID
* status of the session respectively test case
* test case name
* test results
* `record_property` entries
* custom testcase information
* custom session information
Furthermore, the Python logging instance can be extended in order to forward test case runtime logging.
```python
from logging import getLogger
def test_my_runtime_log():
value = 1
getLogger().info(f"Setting value to {value}")
assert value == 1
```
or
```python
from logging import getLogger
def test_my_runtime_log():
value = 1
getLogger('fluent').info(f"Setting value to {value}")
assert value == 1
```
### Fixtures
In order to create your own logger, request the following fixture
```python
def test_my_runtime_log(get_logger):
logger = get_logger('my.Logger')
value = 1
logger.info(f"Setting value to {value}")
assert value == 1
```
If you want to get the current UIDs, use the following fixtures
```python
def test_unique_identifier(session_uid, test_uid):
logger = get_logger('fluent')
logger.info(f"Session ID: {session_uid}")
logger.info(f"Test ID: {test_uid}")
value = 1
assert value == 1
```
### Callbacks
If you want to add custom data to the datasets of the `pytest_sessionstart` and `pytest_runtest_logstart` stages, decorate your callback functions with the following decorators.
```python
from pytest_fluentbit import (
additional_session_information_callback,
additional_test_information_callback
)
@additional_session_information_callback
def provide_more_session_information() -> dict:
return {
"more": "session information"
}
@additional_test_information_callback
def provide_more_test_information() -> dict:
return {
"more": "test information"
}
```
### pytest CLI extensions
The pytest CLI can be called with the following arguments in order to configure fluent-logging.
| argument | description | default |
| ---------------- | --------------------------------------------------------------------------------- | -------- |
| --session-uuid | Use a custom externally created UUID, e.g. link a CI job with the pytest session. | |
| --fluentd-host | Fluentd host address. If not provided, a local Fluentd instance will be called. | |
| --fluentd-port | Fluent host port | 24224 |
| --fluentd-tag | Set a custom Fluentd tag | 'test' |
| --fluentd-label | Set a custom Fluentd label | 'pytest' |
| --extend-logging | Extend the Python logging with a Fluent handler | False |
| --add-docstrings | Add test docstrings to testcase call messages | |
### Ini Configuration Support
Default values of the CLI arguments for a project could also be defined in one of the following ini configuration files:
1. pytest.ini: Arguments are defined under pytest section in the file. This file takes precedence over all other configuration files even if empty.
```python
[pytest]
addopts= --session-uuid="ac2f7600-a079-46cf-a7e0-6408b166364c" --fluentd-port=24224 --fluentd-host=localhost --fluentd-tag='dummytest' --fluentd-label='pytest' --extend-logging
```
2. pyproject.toml: are considered for configuration when they contain a tool.pytest.ini_options section is available
```python
[tool.pytest.ini_options]
addopts="--fluentd-port=24224 --fluentd-host=localhost --fluentd-tag='test' --fluentd-label='pytest' --extend-logging"
```
3. tox.ini: can also be used to hold pytest configuration if they have a [pytest] section.
```python
[pytest]
addopts= --fluentd-port=24224 --fluentd-host=localhost --fluentd-tag='test' --fluentd-label='pytest'
```
If the same option is specified in both CLI and ini file, then CLI option would have higher priority and override the ini file values.
### What data are sent?
pytest-fluent sends any information, e.g. stage information or logging from a test case, as a single chunk. For instance, the data collection from `test_addoptions.py` test looks as following
```json
[
{
"status": "start",
"stage": "session",
"sessionId": "d8f01de3-8416-4801-9406-0ea3d5cfe3c0"
},
{
"status": "start",
"stage": "testcase",
"sessionId": "d8f01de3-8416-4801-9406-0ea3d5cfe3c0",
"testId": "6b444275-4450-4eff-b5d9-8355f0f99ab0",
"name": "test_fluentd_logged_parameters.py::test_base"
},
{
"type": "logging",
"host": "myComputer",
"where": "test_fluentd_logged_parameters.test_base",
"level": "INFO",
"stack_trace": "None",
"message": "Logged from test_base",
"sessionId": "d8f01de3-8416-4801-9406-0ea3d5cfe3c0",
"testId": "6b444275-4450-4eff-b5d9-8355f0f99ab0",
"stage": "testcase"
},
{
"type": "logging",
"host": "myComputer",
"where": "test_fluentd_logged_parameters.test_base",
"level": "INFO",
"stack_trace": "None",
"message": "Logged from test_base",
"sessionId": "d8f01de3-8416-4801-9406-0ea3d5cfe3c0",
"testId": "6b444275-4450-4eff-b5d9-8355f0f99ab0",
"stage": "testcase"
},
{
"name": "test_fluentd_logged_parameters.py::test_base",
"outcome": "passed",
"duration": 0.0013457999999999526,
"markers": {
"test_base": 1,
"test_fluentd_logged_parameters.py": 1,
"test_fluentd_logged_parameters0": 1
},
"stage": "testcase",
"when": "call",
"sessionId": "d8f01de3-8416-4801-9406-0ea3d5cfe3c0",
"testId": "6b444275-4450-4eff-b5d9-8355f0f99ab0"
},
{
"status": "finish",
"stage": "testcase",
"sessionId": "d8f01de3-8416-4801-9406-0ea3d5cfe3c0",
"testId": "6b444275-4450-4eff-b5d9-8355f0f99ab0",
"name": "test_fluentd_logged_parameters.py::test_base"
},
{
"status": "finish",
"duration": 0.00297708511352539,
"stage": "session",
"sessionId": "d8f01de3-8416-4801-9406-0ea3d5cfe3c0"
}
]
```
whereat each object in the array is sent independently via Fluentd.
## Changelog
The changelog.
## Contributing
We welcome any contributions, enhancements, and bug-fixes. Open an [issue](https://github.com/Rohde-Schwarz/pytest-fluent/issues) on [Github](https://github.com) and [submit a pull request](https://github.com/Rohde-Schwarz/pytest-fluent/pulls).
Raw data
{
"_id": null,
"home_page": "",
"name": "pytest-fluentbit",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "pytest,logging,fluent",
"author": "",
"author_email": "Sujay Kanungo <sujay.kanungo@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/f5/31/1f8a40524275615f11ca5c6c4a6b829898df0272f0a810bf8b77bf3fdfed/pytest-fluentbit-0.1.5.tar.gz",
"platform": "Unix",
"description": "# pytest-fluent\n\n[![Documentation](https://readthedocs.org/projects/pytest-fluent/badge/?version=latest)](https://pytest-fluent.readthedocs.io/) [![Build Status](https://github.com/Rohde-Schwarz/pytest-fluent/actions/workflows/tests.yml/badge.svg)](https://github.com/Rohde-Schwarz/pytest-fluent/actions/) [![PyPI Versions](https://img.shields.io/pypi/pyversions/pytest-fluent.svg)](https://pypi.python.org/pypi/pytest-fluent) ![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-fluent) [![PyPI Status](https://img.shields.io/pypi/status/pytest-fluent.svg)](https://pypi.python.org/pypi/pytest-fluent) [![PyPI License](https://img.shields.io/badge/License-MIT-green)](LICENSE)\n\nA Python package in order to extend pytest by fluentd logging\n\n## Description\n\nPytest is one of the most powerful testing suites with a lot of functionality and many plugins. Fluentd is a well-established log collector which is used in many modern web architectures. So, why not putting both worlds together in order to gain real-time log access to your distributed test runs.\n\npytest-fluent enables you to forward your test data immediately to your prefered log-sink from any node spread around your infrastructure. The streamed data are available for each pytest stage and formatted in JSON.\n\nEach pytest session gets an unique identifier (UID) assigned as well as each executed test case. With these UIDs, you can filter easily for sessions and testcase data entries, for instance in your favorite database.\n\n## Installation\n\nThe package is available at pypi.org and can be installed by typing\n\n```shell\npip install pytest-fluentbit\n```\n\n## Usage\n\npytest-fluent-logging forwards meta data from pytest to Fluentd for further processing. The meta data are \n* unique session ID\n* unique test ID\n* status of the session respectively test case\n* test case name\n* test results\n* `record_property` entries\n* custom testcase information\n* custom session information\n \nFurthermore, the Python logging instance can be extended in order to forward test case runtime logging.\n\n```python\nfrom logging import getLogger\n\ndef test_my_runtime_log():\n value = 1\n getLogger().info(f\"Setting value to {value}\")\n assert value == 1\n```\n\nor \n\n```python\nfrom logging import getLogger\n\ndef test_my_runtime_log():\n value = 1\n getLogger('fluent').info(f\"Setting value to {value}\")\n assert value == 1\n```\n\n### Fixtures\n\nIn order to create your own logger, request the following fixture\n\n```python\ndef test_my_runtime_log(get_logger):\n logger = get_logger('my.Logger')\n value = 1\n logger.info(f\"Setting value to {value}\")\n assert value == 1\n```\n\nIf you want to get the current UIDs, use the following fixtures\n\n```python\ndef test_unique_identifier(session_uid, test_uid):\n logger = get_logger('fluent')\n logger.info(f\"Session ID: {session_uid}\")\n logger.info(f\"Test ID: {test_uid}\")\n value = 1\n assert value == 1\n```\n\n### Callbacks\n\nIf you want to add custom data to the datasets of the `pytest_sessionstart` and `pytest_runtest_logstart` stages, decorate your callback functions with the following decorators.\n\n```python\nfrom pytest_fluentbit import (\n additional_session_information_callback,\n additional_test_information_callback\n)\n\n@additional_session_information_callback\ndef provide_more_session_information() -> dict:\n return {\n \"more\": \"session information\"\n }\n\n@additional_test_information_callback\ndef provide_more_test_information() -> dict:\n return {\n \"more\": \"test information\"\n }\n```\n\n### pytest CLI extensions\n\nThe pytest CLI can be called with the following arguments in order to configure fluent-logging.\n\n| argument | description | default |\n| ---------------- | --------------------------------------------------------------------------------- | -------- |\n| --session-uuid | Use a custom externally created UUID, e.g. link a CI job with the pytest session. | |\n| --fluentd-host | Fluentd host address. If not provided, a local Fluentd instance will be called. | |\n| --fluentd-port | Fluent host port | 24224 |\n| --fluentd-tag | Set a custom Fluentd tag | 'test' |\n| --fluentd-label | Set a custom Fluentd label | 'pytest' |\n| --extend-logging | Extend the Python logging with a Fluent handler | False |\n| --add-docstrings | Add test docstrings to testcase call messages | |\n\n### Ini Configuration Support \n\nDefault values of the CLI arguments for a project could also be defined in one of the following ini configuration files:\n\n1. pytest.ini: Arguments are defined under pytest section in the file. This file takes precedence over all other configuration files even if empty. \n\n```python\n[pytest]\naddopts= --session-uuid=\"ac2f7600-a079-46cf-a7e0-6408b166364c\" --fluentd-port=24224 --fluentd-host=localhost --fluentd-tag='dummytest' --fluentd-label='pytest' --extend-logging\n```\n\n2. pyproject.toml: are considered for configuration when they contain a tool.pytest.ini_options section is available\n\n```python\n[tool.pytest.ini_options]\naddopts=\"--fluentd-port=24224 --fluentd-host=localhost --fluentd-tag='test' --fluentd-label='pytest' --extend-logging\"\n```\n\n3. tox.ini: can also be used to hold pytest configuration if they have a [pytest] section.\n\n```python\n[pytest]\naddopts= --fluentd-port=24224 --fluentd-host=localhost --fluentd-tag='test' --fluentd-label='pytest'\n```\n\nIf the same option is specified in both CLI and ini file, then CLI option would have higher priority and override the ini file values.\n\n\n### What data are sent?\n\npytest-fluent sends any information, e.g. stage information or logging from a test case, as a single chunk. For instance, the data collection from `test_addoptions.py` test looks as following\n\n```json\n[\n {\n \"status\": \"start\",\n \"stage\": \"session\",\n \"sessionId\": \"d8f01de3-8416-4801-9406-0ea3d5cfe3c0\"\n },\n {\n \"status\": \"start\",\n \"stage\": \"testcase\",\n \"sessionId\": \"d8f01de3-8416-4801-9406-0ea3d5cfe3c0\",\n \"testId\": \"6b444275-4450-4eff-b5d9-8355f0f99ab0\",\n \"name\": \"test_fluentd_logged_parameters.py::test_base\"\n },\n {\n \"type\": \"logging\",\n \"host\": \"myComputer\",\n \"where\": \"test_fluentd_logged_parameters.test_base\",\n \"level\": \"INFO\",\n \"stack_trace\": \"None\",\n \"message\": \"Logged from test_base\",\n \"sessionId\": \"d8f01de3-8416-4801-9406-0ea3d5cfe3c0\",\n \"testId\": \"6b444275-4450-4eff-b5d9-8355f0f99ab0\",\n \"stage\": \"testcase\"\n },\n {\n \"type\": \"logging\",\n \"host\": \"myComputer\",\n \"where\": \"test_fluentd_logged_parameters.test_base\",\n \"level\": \"INFO\",\n \"stack_trace\": \"None\",\n \"message\": \"Logged from test_base\",\n \"sessionId\": \"d8f01de3-8416-4801-9406-0ea3d5cfe3c0\",\n \"testId\": \"6b444275-4450-4eff-b5d9-8355f0f99ab0\",\n \"stage\": \"testcase\"\n },\n {\n \"name\": \"test_fluentd_logged_parameters.py::test_base\",\n \"outcome\": \"passed\",\n \"duration\": 0.0013457999999999526,\n \"markers\": {\n \"test_base\": 1,\n \"test_fluentd_logged_parameters.py\": 1,\n \"test_fluentd_logged_parameters0\": 1\n },\n \"stage\": \"testcase\",\n \"when\": \"call\",\n \"sessionId\": \"d8f01de3-8416-4801-9406-0ea3d5cfe3c0\",\n \"testId\": \"6b444275-4450-4eff-b5d9-8355f0f99ab0\"\n },\n {\n \"status\": \"finish\",\n \"stage\": \"testcase\",\n \"sessionId\": \"d8f01de3-8416-4801-9406-0ea3d5cfe3c0\",\n \"testId\": \"6b444275-4450-4eff-b5d9-8355f0f99ab0\",\n \"name\": \"test_fluentd_logged_parameters.py::test_base\"\n },\n {\n \"status\": \"finish\",\n \"duration\": 0.00297708511352539,\n \"stage\": \"session\",\n \"sessionId\": \"d8f01de3-8416-4801-9406-0ea3d5cfe3c0\"\n }\n]\n```\n\nwhereat each object in the array is sent independently via Fluentd.\n\n\n## Changelog\n\nThe changelog.\n\n## Contributing\n\nWe welcome any contributions, enhancements, and bug-fixes. Open an [issue](https://github.com/Rohde-Schwarz/pytest-fluent/issues) on [Github](https://github.com) and [submit a pull request](https://github.com/Rohde-Schwarz/pytest-fluent/pulls).\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A pytest plugin in order to provide logs via fluentbit",
"version": "0.1.5",
"project_urls": {
"project": "https://github.com/sujay2002/pytest-fluentbit"
},
"split_keywords": [
"pytest",
"logging",
"fluent"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f05ee9373c8d79c49d88caa3e4592571e4ffcb49efb02f1fdd0134fb33b925c2",
"md5": "b977b77a8d6142b3d19bcbe1a0dbaa98",
"sha256": "e01ef219b01edc21587eede360e4f630d893d95118adb61f7bf6e8f0a7a577cf"
},
"downloads": -1,
"filename": "pytest_fluentbit-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b977b77a8d6142b3d19bcbe1a0dbaa98",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 11080,
"upload_time": "2023-06-16T22:07:50",
"upload_time_iso_8601": "2023-06-16T22:07:50.590729Z",
"url": "https://files.pythonhosted.org/packages/f0/5e/e9373c8d79c49d88caa3e4592571e4ffcb49efb02f1fdd0134fb33b925c2/pytest_fluentbit-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f5311f8a40524275615f11ca5c6c4a6b829898df0272f0a810bf8b77bf3fdfed",
"md5": "2382ce3692e4375b5033b5553370a211",
"sha256": "cc37856eb035a744f9e9c986b8c4a9806c87520fe7f456040567af001c6152ad"
},
"downloads": -1,
"filename": "pytest-fluentbit-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "2382ce3692e4375b5033b5553370a211",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 18757,
"upload_time": "2023-06-16T22:07:52",
"upload_time_iso_8601": "2023-06-16T22:07:52.172607Z",
"url": "https://files.pythonhosted.org/packages/f5/31/1f8a40524275615f11ca5c6c4a6b829898df0272f0a810bf8b77bf3fdfed/pytest-fluentbit-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-16 22:07:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sujay2002",
"github_project": "pytest-fluentbit",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "pytest-fluentbit"
}