pytest-lazy-fixtures


Namepytest-lazy-fixtures JSON
Version 1.3.2 PyPI version JSON
download
home_pageNone
SummaryAllows you to use fixtures in @pytest.mark.parametrize.
upload_time2025-07-17 22:44:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords fixture lazy pytest tests
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-lazy-fixtures

[![codecov](https://codecov.io/gh/dev-petrov/pytest-lazy-fixtures/branch/master/graph/badge.svg)](https://codecov.io/gh/dev-petrov/pytest-lazy-fixtures)
[![CI](https://github.com/dev-petrov/pytest-lazy-fixtures/workflows/CI/badge.svg)](https://github.com/dev-petrov/pytest-lazy-fixtures/actions/workflows/ci-test.yml)
[![PyPI version](https://badge.fury.io/py/pytest-lazy-fixtures.svg)](https://pypi.org/project/pytest-lazy-fixtures/)
[![PyPI downloads](https://img.shields.io/pypi/dm/pytest-lazy-fixtures)](https://pypistats.org/packages/pytest-lazy-fixtures)

Use your fixtures in `@pytest.mark.parametrize`.

This project was inspired by [pytest-lazy-fixture](https://github.com/TvoroG/pytest-lazy-fixture).

Improvements that have been made in this project:

1. You can use fixtures in any data structures
2. You can access the attributes of fixtures
3. You can use functions in fixtures
4. It is compatible with [pytest-deadfixtures](https://github.com/jllorencetti/pytest-deadfixtures)

## Installation

```shell
pip install pytest-lazy-fixtures
```

## Usage

To use your fixtures inside `@pytest.mark.parametrize` you can use `lf` (`lazy_fixture`).

```python
import pytest
from pytest_lazy_fixtures import lf

@pytest.fixture()
def one():
    return 1

@pytest.mark.parametrize('arg1,arg2', [('val1', lf('one'))])
def test_func(arg1, arg2):
    assert arg2 == 1
```

`lf` can be used with any data structures. For example, in the following example, `lf` is used in the dictionary:

```python
import pytest
from pytest_lazy_fixtures import lf

@pytest.fixture()
def one():
    return 1

@pytest.mark.parametrize('arg1,arg2', [('val1', {"value": lf('one')})])
def test_func(arg1, arg2):
    assert arg2 == {"value": 1}
```

You can also specify getting an attribute through a dot:

```python
import pytest
from pytest_lazy_fixtures import lf

class Entity:
    def __init__(self, value):
        self.value = value

@pytest.fixture()
def one():
    return Entity(1)

@pytest.mark.parametrize('arg1,arg2', [('val1', lf('one.value'))])
def test_func(arg1, arg2):
    assert arg2 == 1
```

And there is some useful wrapper called `lfc` (`lazy_fixture_callable`).
It can work with any callable and your fixtures, e.g.

```python
import pytest
from pytest_lazy_fixtures import lf, lfc

class Entity:
    def __init__(self, value):
        self.value = value

    def __str__(self) -> str:
        return str(self.value)

    def sum(self, value: int) -> int:
        return self.value + value

@pytest.fixture()
def entity():
    return Entity(1)

@pytest.fixture()
def two():
    return 2

@pytest.fixture()
def three():
    return 3

@pytest.fixture()
def entity_format():
    def _entity_format(entity: Entity):
        return {"value": entity.value}

    return _entity_format

@pytest.mark.parametrize(
    "message",
    [
        lfc(
            "There is two lazy fixture args, {} and {}! And one kwarg {field}! And also simple value {simple}".format,
            lf("entity"),
            lf("two"),
            field=lf("three"),
            simple="value",
        ),
    ],
)
def test_lazy_fixture_callable_with_func(message):
    assert message == "There is two lazy fixture args, 1 and 2! And one kwarg 3! And also simple value value"


@pytest.mark.parametrize("formatted", [lfc("entity_format", lf("entity"))])
def test_lazy_fixture_callable_with_lf(formatted, entity):
    assert formatted == {"value": entity.value}


@pytest.mark.parametrize("result", [lfc("entity.sum", lf("two"))])
def test_lazy_fixture_callable_with_attr_lf(result):
    assert result == 3
```

## Contributing

Contributions are very welcome. Tests can be run with `pytest`.

## License

Distributed under the terms of the `MIT` license, `pytest-lazy-fixtures` is free and open source software

## Issues

If you encounter any problems, please file an issue along with a detailed description.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytest-lazy-fixtures",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "fixture, lazy, pytest, tests",
    "author": null,
    "author_email": "Petrov Anton <antonp2@yandex.ru>",
    "download_url": "https://files.pythonhosted.org/packages/95/17/ff51472404b5597c8e983ff16e61101d51e63d3e19d7d3d9ace4c404ff61/pytest_lazy_fixtures-1.3.2.tar.gz",
    "platform": null,
    "description": "# pytest-lazy-fixtures\n\n[![codecov](https://codecov.io/gh/dev-petrov/pytest-lazy-fixtures/branch/master/graph/badge.svg)](https://codecov.io/gh/dev-petrov/pytest-lazy-fixtures)\n[![CI](https://github.com/dev-petrov/pytest-lazy-fixtures/workflows/CI/badge.svg)](https://github.com/dev-petrov/pytest-lazy-fixtures/actions/workflows/ci-test.yml)\n[![PyPI version](https://badge.fury.io/py/pytest-lazy-fixtures.svg)](https://pypi.org/project/pytest-lazy-fixtures/)\n[![PyPI downloads](https://img.shields.io/pypi/dm/pytest-lazy-fixtures)](https://pypistats.org/packages/pytest-lazy-fixtures)\n\nUse your fixtures in `@pytest.mark.parametrize`.\n\nThis project was inspired by [pytest-lazy-fixture](https://github.com/TvoroG/pytest-lazy-fixture).\n\nImprovements that have been made in this project:\n\n1. You can use fixtures in any data structures\n2. You can access the attributes of fixtures\n3. You can use functions in fixtures\n4. It is compatible with [pytest-deadfixtures](https://github.com/jllorencetti/pytest-deadfixtures)\n\n## Installation\n\n```shell\npip install pytest-lazy-fixtures\n```\n\n## Usage\n\nTo use your fixtures inside `@pytest.mark.parametrize` you can use `lf` (`lazy_fixture`).\n\n```python\nimport pytest\nfrom pytest_lazy_fixtures import lf\n\n@pytest.fixture()\ndef one():\n    return 1\n\n@pytest.mark.parametrize('arg1,arg2', [('val1', lf('one'))])\ndef test_func(arg1, arg2):\n    assert arg2 == 1\n```\n\n`lf` can be used with any data structures. For example, in the following example, `lf` is used in the dictionary:\n\n```python\nimport pytest\nfrom pytest_lazy_fixtures import lf\n\n@pytest.fixture()\ndef one():\n    return 1\n\n@pytest.mark.parametrize('arg1,arg2', [('val1', {\"value\": lf('one')})])\ndef test_func(arg1, arg2):\n    assert arg2 == {\"value\": 1}\n```\n\nYou can also specify getting an attribute through a dot:\n\n```python\nimport pytest\nfrom pytest_lazy_fixtures import lf\n\nclass Entity:\n    def __init__(self, value):\n        self.value = value\n\n@pytest.fixture()\ndef one():\n    return Entity(1)\n\n@pytest.mark.parametrize('arg1,arg2', [('val1', lf('one.value'))])\ndef test_func(arg1, arg2):\n    assert arg2 == 1\n```\n\nAnd there is some useful wrapper called `lfc` (`lazy_fixture_callable`).\nIt can work with any callable and your fixtures, e.g.\n\n```python\nimport pytest\nfrom pytest_lazy_fixtures import lf, lfc\n\nclass Entity:\n    def __init__(self, value):\n        self.value = value\n\n    def __str__(self) -> str:\n        return str(self.value)\n\n    def sum(self, value: int) -> int:\n        return self.value + value\n\n@pytest.fixture()\ndef entity():\n    return Entity(1)\n\n@pytest.fixture()\ndef two():\n    return 2\n\n@pytest.fixture()\ndef three():\n    return 3\n\n@pytest.fixture()\ndef entity_format():\n    def _entity_format(entity: Entity):\n        return {\"value\": entity.value}\n\n    return _entity_format\n\n@pytest.mark.parametrize(\n    \"message\",\n    [\n        lfc(\n            \"There is two lazy fixture args, {} and {}! And one kwarg {field}! And also simple value {simple}\".format,\n            lf(\"entity\"),\n            lf(\"two\"),\n            field=lf(\"three\"),\n            simple=\"value\",\n        ),\n    ],\n)\ndef test_lazy_fixture_callable_with_func(message):\n    assert message == \"There is two lazy fixture args, 1 and 2! And one kwarg 3! And also simple value value\"\n\n\n@pytest.mark.parametrize(\"formatted\", [lfc(\"entity_format\", lf(\"entity\"))])\ndef test_lazy_fixture_callable_with_lf(formatted, entity):\n    assert formatted == {\"value\": entity.value}\n\n\n@pytest.mark.parametrize(\"result\", [lfc(\"entity.sum\", lf(\"two\"))])\ndef test_lazy_fixture_callable_with_attr_lf(result):\n    assert result == 3\n```\n\n## Contributing\n\nContributions are very welcome. Tests can be run with `pytest`.\n\n## License\n\nDistributed under the terms of the `MIT` license, `pytest-lazy-fixtures` is free and open source software\n\n## Issues\n\nIf you encounter any problems, please file an issue along with a detailed description.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Allows you to use fixtures in @pytest.mark.parametrize.",
    "version": "1.3.2",
    "project_urls": {
        "Homepage": "https://github.com/dev-petrov/pytest-lazy-fixtures",
        "Repository": "https://github.com/dev-petrov/pytest-lazy-fixtures"
    },
    "split_keywords": [
        "fixture",
        " lazy",
        " pytest",
        " tests"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "631724fb2218d850800dfad9c12fc31935900304f2bfefedfd060230a4a684f3",
                "md5": "212a92d1aa7c1233c808a5e05113a50a",
                "sha256": "a2a7096c6a4f71f0160eaa07fe03f93c006505dd7283df075cd26fcc2b654754"
            },
            "downloads": -1,
            "filename": "pytest_lazy_fixtures-1.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "212a92d1aa7c1233c808a5e05113a50a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8389,
            "upload_time": "2025-07-17T22:44:46",
            "upload_time_iso_8601": "2025-07-17T22:44:46.053794Z",
            "url": "https://files.pythonhosted.org/packages/63/17/24fb2218d850800dfad9c12fc31935900304f2bfefedfd060230a4a684f3/pytest_lazy_fixtures-1.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9517ff51472404b5597c8e983ff16e61101d51e63d3e19d7d3d9ace4c404ff61",
                "md5": "a21137ebad16c3e344be6e4ffb2ae4c1",
                "sha256": "76bac6772e97173828d49551695cc6e3927c7c86c65cd19d4cccb0c14a45f821"
            },
            "downloads": -1,
            "filename": "pytest_lazy_fixtures-1.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a21137ebad16c3e344be6e4ffb2ae4c1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 34114,
            "upload_time": "2025-07-17T22:44:47",
            "upload_time_iso_8601": "2025-07-17T22:44:47.086215Z",
            "url": "https://files.pythonhosted.org/packages/95/17/ff51472404b5597c8e983ff16e61101d51e63d3e19d7d3d9ace4c404ff61/pytest_lazy_fixtures-1.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-17 22:44:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dev-petrov",
    "github_project": "pytest-lazy-fixtures",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-lazy-fixtures"
}
        
Elapsed time: 1.68373s