pytest-node-dependency


Namepytest-node-dependency JSON
Version 1.4.0 PyPI version JSON
download
home_pagehttps://github.com/Formartha/pytest-node-dependency
Summarypytest plugin for controlling execution flow
upload_time2024-04-10 12:21:25
maintainerNone
docs_urlNone
authorMor Dabastany
requires_pythonNone
licenseMIT
keywords pyest-node-dependency
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ------

[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit)
![PyPI](https://img.shields.io/pypi/v/pytest-node-dependency)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-node-dependency)

What?
------
pytest-node-dependency is a pytest plugin that allows you to define dependencies between tests and reorder their execution based on those dependencies. This plugin ensures that tests with dependencies run after their required prerequisites have completed successfully.

A unique feature of the plugin is that if you set a test to depend on another one, the plugin will check if the test being depended upon failed. If that's the case, it will mark the current test as 'expected to fail' (xfail).

How to install?
----------
```
pip install pytest-node-dependency
```

How to use?
-----------------------------------------------------
To set up a test dependency, decorate the test function with the `depends` mark and provide a list of dependencies via the `on` keyword argument to the decorator. Dependencies can be specified by name only when in the same file as the test being decorated or by the pytest node path for tests in other files/classes.

```
import pytest


def test_second(request):
    print("second")
    assert request.session.items[1].name == 'test_second'


@pytest.mark.depends(on=["test_plugin.py::test_second"])
def test_last(request):
    print("last")
    assert request.session.items[2].name == 'test_last'


def test_first(request):
    print("first")
    assert request.session.items[0].name == 'test_first'
```

Xdist adoption:
---------------
The way xdist plugin works is by utilizing multiple cores and spreads the tests among them.
The problem with the plugin is that if you wish to use reordering, you probably want to set some dependency among the tests,
However, the xdist plugin will break it.

For that, you should set the group for the tests. The group means that a gateway worker will collect the tests, and will 
place all the grouped tests in a single gateway worker. 
This will lead creation of serial testing among parallel exectuion.

```
import pytest

@pytest.mark.depends(xdist_group='a')
def test_second(request):
    print("second")
    assert request.session.items[1].name == 'test_second'


@pytest.mark.depends(on=["test_plugin.py::test_second"], xdist_group='a')
def test_last(request):
    print("last")
    assert request.session.items[2].name == 'test_last'


def test_first(request):
    print("first")
    assert request.session.items[0].name == 'test_first'
```


Limitations and known issues:
-----------------------------------------------------
* All the tests without dependency (both dependent-on) will run first, then, all tests with connections will run
(e.g. the list of items will be as described)
* Currently, automated xfail is enabled, it should be configurable.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Formartha/pytest-node-dependency",
    "name": "pytest-node-dependency",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "pyest-node-dependency",
    "author": "Mor Dabastany",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/3c/eb/d97625c9c64d9e0daa609971e4cc9b348be9580d838ee9a60cd541a085db/pytest-node-dependency-1.4.0.tar.gz",
    "platform": null,
    "description": "------\n\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit)\n![PyPI](https://img.shields.io/pypi/v/pytest-node-dependency)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-node-dependency)\n\nWhat?\n------\npytest-node-dependency is a pytest plugin that allows you to define dependencies between tests and reorder their execution based on those dependencies. This plugin ensures that tests with dependencies run after their required prerequisites have completed successfully.\n\nA unique feature of the plugin is that if you set a test to depend on another one, the plugin will check if the test being depended upon failed. If that's the case, it will mark the current test as 'expected to fail' (xfail).\n\nHow to install?\n----------\n```\npip install pytest-node-dependency\n```\n\nHow to use?\n-----------------------------------------------------\nTo set up a test dependency, decorate the test function with the `depends` mark and provide a list of dependencies via the `on` keyword argument to the decorator. Dependencies can be specified by name only when in the same file as the test being decorated or by the pytest node path for tests in other files/classes.\n\n```\nimport pytest\n\n\ndef test_second(request):\n    print(\"second\")\n    assert request.session.items[1].name == 'test_second'\n\n\n@pytest.mark.depends(on=[\"test_plugin.py::test_second\"])\ndef test_last(request):\n    print(\"last\")\n    assert request.session.items[2].name == 'test_last'\n\n\ndef test_first(request):\n    print(\"first\")\n    assert request.session.items[0].name == 'test_first'\n```\n\nXdist adoption:\n---------------\nThe way xdist plugin works is by utilizing multiple cores and spreads the tests among them.\nThe problem with the plugin is that if you wish to use reordering, you probably want to set some dependency among the tests,\nHowever, the xdist plugin will break it.\n\nFor that, you should set the group for the tests. The group means that a gateway worker will collect the tests, and will \nplace all the grouped tests in a single gateway worker. \nThis will lead creation of serial testing among parallel exectuion.\n\n```\nimport pytest\n\n@pytest.mark.depends(xdist_group='a')\ndef test_second(request):\n    print(\"second\")\n    assert request.session.items[1].name == 'test_second'\n\n\n@pytest.mark.depends(on=[\"test_plugin.py::test_second\"], xdist_group='a')\ndef test_last(request):\n    print(\"last\")\n    assert request.session.items[2].name == 'test_last'\n\n\ndef test_first(request):\n    print(\"first\")\n    assert request.session.items[0].name == 'test_first'\n```\n\n\nLimitations and known issues:\n-----------------------------------------------------\n* All the tests without dependency (both dependent-on) will run first, then, all tests with connections will run\n(e.g. the list of items will be as described)\n* Currently, automated xfail is enabled, it should be configurable.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pytest plugin for controlling execution flow",
    "version": "1.4.0",
    "project_urls": {
        "Homepage": "https://github.com/Formartha/pytest-node-dependency"
    },
    "split_keywords": [
        "pyest-node-dependency"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c4c4e7eeb9c3de52a0801953aa1a5eff798cc4bbaae88b9aeedefe11cf86d83",
                "md5": "896186cc043c86f551afeb8e0e15a182",
                "sha256": "6775d4ea885d02714e56285a78d403009bcf3949ad3ac9edad0cab9a299e258a"
            },
            "downloads": -1,
            "filename": "pytest_node_dependency-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "896186cc043c86f551afeb8e0e15a182",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6158,
            "upload_time": "2024-04-10T12:21:23",
            "upload_time_iso_8601": "2024-04-10T12:21:23.794573Z",
            "url": "https://files.pythonhosted.org/packages/1c/4c/4e7eeb9c3de52a0801953aa1a5eff798cc4bbaae88b9aeedefe11cf86d83/pytest_node_dependency-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3cebd97625c9c64d9e0daa609971e4cc9b348be9580d838ee9a60cd541a085db",
                "md5": "ed08c377efc3274964166a162b5de640",
                "sha256": "1aa3fe11a08edff02d0c86d5ce5302aa0ffd8477164f5cb39d4dbfee81508642"
            },
            "downloads": -1,
            "filename": "pytest-node-dependency-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ed08c377efc3274964166a162b5de640",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5678,
            "upload_time": "2024-04-10T12:21:25",
            "upload_time_iso_8601": "2024-04-10T12:21:25.652321Z",
            "url": "https://files.pythonhosted.org/packages/3c/eb/d97625c9c64d9e0daa609971e4cc9b348be9580d838ee9a60cd541a085db/pytest-node-dependency-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-10 12:21:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Formartha",
    "github_project": "pytest-node-dependency",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-node-dependency"
}
        
Elapsed time: 0.24175s