diff --git a/pyproject.toml b/pyproject.toml index 9f7b713..369f382 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.md" diff --git a/pytest_lazy_fixtures/loader.py b/pytest_lazy_fixtures/loader.py index 330b6f1..3c675c2 100644 --- a/pytest_lazy_fixtures/loader.py +++ b/pytest_lazy_fixtures/loader.py @@ -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 diff --git a/tests/entity.py b/tests/entity.py index f4c73cf..46d6685 100644 --- a/tests/entity.py +++ b/tests/entity.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from typing import NamedTuple @dataclass @@ -7,3 +8,8 @@ class Entity: def sum(self, value: int) -> int: return self.value + value + + +class DataNamedTuple(NamedTuple): + a: int + b: int diff --git a/tests/tests.py b/tests/tests.py index 5135203..8d9a2fe 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -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(): @@ -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