pytest-multilog


Namepytest-multilog JSON
Version 1.4.2 PyPI version JSON
download
home_pagehttps://github.com/dynod/pytest-multilog
SummaryMulti-process logs handling and other helpers for pytest
upload_time2023-01-17 07:48:05
maintainerThe dynod project
docs_urlNone
authorThe dynod project
requires_python
licenseMozilla Public License Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-multilog
A pytest plugin to persist logs from parallel test processes (and other helpers)

<!-- NMK-BADGES-BEGIN -->
[![License: MPL](https://img.shields.io/github/license/dynod/pytest-multilog)](https://github.com/dynod/pytest-multilog/blob/main/LICENSE)
[![Checks](https://img.shields.io/github/actions/workflow/status/dynod/pytest-multilog/build.yml?branch=main&label=build%20%26%20u.t.)](https://github.com/dynod/pytest-multilog/actions?query=branch%3Amain)
[![Issues](https://img.shields.io/github/issues-search/dynod/pytest-multilog?label=issues&query=is%3Aopen+is%3Aissue)](https://github.com/dynod/pytest-multilog/issues?q=is%3Aopen+is%3Aissue)
[![Supported python versions](https://img.shields.io/badge/python-3.8%20--%203.11-blue)](https://www.python.org/)
[![PyPI](https://img.shields.io/pypi/v/pytest-multilog)](https://pypi.org/project/pytest-multilog/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Flake8 analysis result](https://img.shields.io/badge/flake8-0-green)](https://flake8.pycqa.org/)
[![Code coverage](https://img.shields.io/codecov/c/github/dynod/pytest-multilog)](https://app.codecov.io/gh/dynod/pytest-multilog)
<!-- NMK-BADGES-END -->

## Usage
To use the multilog feature, a test class just needs to inherit from the **`TestHelper`** class:

```python
from pytest_multilog import TestHelper

class TestCustom(TestHelper):
    def test_custom(self):
        # Custom test implementation
        ...
```

The **`TestHelper`** class declares a **`logs`** fixture which will be automatically used by its children classes.

## Behavior and attributes

### Root folder
The **`TestHelper`** class provides a **`root_folder`** property, matching with the **pytest** root folder.

### Output folder
The **`TestHelper`** class provides a **`output_folder`** property, where all files will be written. It's set to **`output_folder / "out" / "tests"`**

### Test name
Each test is associated to a name (provided in **`TestHelper.test_name`**), computed from the file name, the class name and the method name.

E.g. for the snippet above, if stored in a **`test_custom.py`** file, the test name will be: **test_custom_TestCustom_test_custom**.

### Current worker
In multi-process environment (**pytest** was invoked with **-n X** argument), the current worker name is provided in **`TestHelper.worker`** attribute.
It's set to **"master"** in single-process environment.

The class also provides a **`TestHelper.worker_index`** attribute, giving the working index as an integer value (will be set to 0 for **"master"**).

### Test folder
Test logs will be written in a **pytest.log** file (path provided in **`TestHelper.test_logs`**), stored in each test folder (provided in **`TestHelper.test_folder`** attribute):
* While the test is running, it's set to **`TestHelper.output_root / "__running__" / TestHelper.worker / TestHelper.test_name`**
* Once the test is terminated, the folder is moved directly under the output root one.

It means that during the test execution, it's possible to check which test is running on which worker 
(easing troubleshooting situations where a given worker is blocked)

### Checking logs
It is possible to verify if some strings are present in the current test log, by using the **`TestHelper.check_logs`** method.
It takes as input argument:
* either a simple string/Pattern or a list of strings/Patterns:
  * strings will be simply checked to be contained in the whole log
  * Patterns will be searched line by line (more flexible, but slower)
* an optional timeout
* a **`check_order`** parameter to verify patterns order (default if False)

The method will assert if all inputs are found in the log (within the expected timeout, if any).

By default, expected patterns order doesn't matter.
If **`check_order`** parameter is set to True, patterns will be expected in the input order, and check will fail if the order doesn't match.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dynod/pytest-multilog",
    "name": "pytest-multilog",
    "maintainer": "The dynod project",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "The dynod project",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/52/55/17e06cfb42dab3efb6b8914aa08df2fd87405fa1183a8e977ed3a097b52f/pytest-multilog-1.4.2.tar.gz",
    "platform": null,
    "description": "# pytest-multilog\nA pytest plugin to persist logs from parallel test processes (and other helpers)\n\n<!-- NMK-BADGES-BEGIN -->\n[![License: MPL](https://img.shields.io/github/license/dynod/pytest-multilog)](https://github.com/dynod/pytest-multilog/blob/main/LICENSE)\n[![Checks](https://img.shields.io/github/actions/workflow/status/dynod/pytest-multilog/build.yml?branch=main&label=build%20%26%20u.t.)](https://github.com/dynod/pytest-multilog/actions?query=branch%3Amain)\n[![Issues](https://img.shields.io/github/issues-search/dynod/pytest-multilog?label=issues&query=is%3Aopen+is%3Aissue)](https://github.com/dynod/pytest-multilog/issues?q=is%3Aopen+is%3Aissue)\n[![Supported python versions](https://img.shields.io/badge/python-3.8%20--%203.11-blue)](https://www.python.org/)\n[![PyPI](https://img.shields.io/pypi/v/pytest-multilog)](https://pypi.org/project/pytest-multilog/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Flake8 analysis result](https://img.shields.io/badge/flake8-0-green)](https://flake8.pycqa.org/)\n[![Code coverage](https://img.shields.io/codecov/c/github/dynod/pytest-multilog)](https://app.codecov.io/gh/dynod/pytest-multilog)\n<!-- NMK-BADGES-END -->\n\n## Usage\nTo use the multilog feature, a test class just needs to inherit from the **`TestHelper`** class:\n\n```python\nfrom pytest_multilog import TestHelper\n\nclass TestCustom(TestHelper):\n    def test_custom(self):\n        # Custom test implementation\n        ...\n```\n\nThe **`TestHelper`** class declares a **`logs`** fixture which will be automatically used by its children classes.\n\n## Behavior and attributes\n\n### Root folder\nThe **`TestHelper`** class provides a **`root_folder`** property, matching with the **pytest** root folder.\n\n### Output folder\nThe **`TestHelper`** class provides a **`output_folder`** property, where all files will be written. It's set to **`output_folder / \"out\" / \"tests\"`**\n\n### Test name\nEach test is associated to a name (provided in **`TestHelper.test_name`**), computed from the file name, the class name and the method name.\n\nE.g. for the snippet above, if stored in a **`test_custom.py`** file, the test name will be: **test_custom_TestCustom_test_custom**.\n\n### Current worker\nIn multi-process environment (**pytest** was invoked with **-n X** argument), the current worker name is provided in **`TestHelper.worker`** attribute.\nIt's set to **\"master\"** in single-process environment.\n\nThe class also provides a **`TestHelper.worker_index`** attribute, giving the working index as an integer value (will be set to 0 for **\"master\"**).\n\n### Test folder\nTest logs will be written in a **pytest.log** file (path provided in **`TestHelper.test_logs`**), stored in each test folder (provided in **`TestHelper.test_folder`** attribute):\n* While the test is running, it's set to **`TestHelper.output_root / \"__running__\" / TestHelper.worker / TestHelper.test_name`**\n* Once the test is terminated, the folder is moved directly under the output root one.\n\nIt means that during the test execution, it's possible to check which test is running on which worker \n(easing troubleshooting situations where a given worker is blocked)\n\n### Checking logs\nIt is possible to verify if some strings are present in the current test log, by using the **`TestHelper.check_logs`** method.\nIt takes as input argument:\n* either a simple string/Pattern or a list of strings/Patterns:\n  * strings will be simply checked to be contained in the whole log\n  * Patterns will be searched line by line (more flexible, but slower)\n* an optional timeout\n* a **`check_order`** parameter to verify patterns order (default if False)\n\nThe method will assert if all inputs are found in the log (within the expected timeout, if any).\n\nBy default, expected patterns order doesn't matter.\nIf **`check_order`** parameter is set to True, patterns will be expected in the input order, and check will fail if the order doesn't match.\n\n\n",
    "bugtrack_url": null,
    "license": "Mozilla Public License Version 2.0",
    "summary": "Multi-process logs handling and other helpers for pytest",
    "version": "1.4.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "10d2e8be0762239fb9d0b2525321fc6f9b64aa55d5429fce9bbb5040d3a2399f",
                "md5": "b016455611eaeab6ef3a5e34d8cb34ab",
                "sha256": "7b942b52f3031facf326e7d57bf0813b09e2724a143b610195ed3c4d5526f709"
            },
            "downloads": -1,
            "filename": "pytest_multilog-1.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b016455611eaeab6ef3a5e34d8cb34ab",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10711,
            "upload_time": "2023-01-17T07:48:04",
            "upload_time_iso_8601": "2023-01-17T07:48:04.070501Z",
            "url": "https://files.pythonhosted.org/packages/10/d2/e8be0762239fb9d0b2525321fc6f9b64aa55d5429fce9bbb5040d3a2399f/pytest_multilog-1.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "525517e06cfb42dab3efb6b8914aa08df2fd87405fa1183a8e977ed3a097b52f",
                "md5": "d646d9d073a1f1a43f38c5e6f86f4d61",
                "sha256": "0ccea0488cf4f1f5638454081ca076f733428303134bf8d8ce319a86eb834731"
            },
            "downloads": -1,
            "filename": "pytest-multilog-1.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d646d9d073a1f1a43f38c5e6f86f4d61",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10624,
            "upload_time": "2023-01-17T07:48:05",
            "upload_time_iso_8601": "2023-01-17T07:48:05.268429Z",
            "url": "https://files.pythonhosted.org/packages/52/55/17e06cfb42dab3efb6b8914aa08df2fd87405fa1183a8e977ed3a097b52f/pytest-multilog-1.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-17 07:48:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "dynod",
    "github_project": "pytest-multilog",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pytest-multilog"
}
        
Elapsed time: 0.06918s