Skip to content

Commit

Permalink
Fix named tuple issue (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-petrov authored Feb 6, 2024
1 parent c8203dd commit 182bfe9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytest-lazy-fixtures"
version = "1.0.3"
version = "1.0.4"
description = "Allows you to use fixtures in @pytest.mark.parametrize."
authors = ["Petrov Anton <antonp2@yandex.ru>"]
readme = "README.md"
Expand Down
6 changes: 4 additions & 2 deletions pytest_lazy_fixtures/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def load_lazy_fixtures(value, request: pytest.FixtureRequest):
)
if isinstance(value, LazyFixtureWrapper):
return value.load_fixture(request)
if isinstance(value, dict):
# we need to check exact type
if type(value) is dict: # noqa: E721
return {key: load_lazy_fixtures(value, request) for key, value in value.items()}
elif isinstance(value, (list, tuple, set)):
# we need to check exact type
elif type(value) in {list, tuple, set}:
return type(value)([load_lazy_fixtures(value, request) for value in value])
return value
6 changes: 6 additions & 0 deletions tests/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from typing import NamedTuple


@dataclass
Expand All @@ -7,3 +8,8 @@ class Entity:

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


class DataNamedTuple(NamedTuple):
a: int
b: int
8 changes: 7 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pytest_lazy_fixtures import lf, lfc
from pytest_lazy_fixtures.lazy_fixture import LazyFixtureWrapper
from pytest_lazy_fixtures.lazy_fixture_callable import LazyFixtureCallableWrapper
from tests.entity import Entity
from tests.entity import DataNamedTuple, Entity


def test_lazy_fixture_repr():
Expand Down Expand Up @@ -73,3 +73,9 @@ def test_lazy_fixture_callable_with_lf(formatted, entity):
@pytest.mark.parametrize("result", [lfc("entity.sum", lf("two"))])
def test_lazy_fixture_callable_with_attr_lf(result):
assert result == 3


@pytest.mark.parametrize("data", [DataNamedTuple(a=1, b=2)])
def test(data):
assert data.a == 1
assert data.b == 2

0 comments on commit 182bfe9

Please sign in to comment.