Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
pydantic-version: ["1.10", "2.0"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
pydantic-version: ["2.0"]
sqla-version: ["1.4", "2"]
exclude:
- pydantic-version: "1.10"
sqla-version: "1.4"
steps:
- name: Check out repository
uses: actions/checkout@v5
Expand Down
11 changes: 7 additions & 4 deletions polyfactory/factories/pydantic_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from collections.abc import Mapping
from contextlib import suppress
from datetime import timezone
Expand Down Expand Up @@ -83,10 +84,12 @@
from pydantic_core import PydanticUndefined as UndefinedV2
from pydantic_core import to_json

import pydantic.v1 as pydantic_v1 # type: ignore[no-redef]
from pydantic.v1 import BaseModel as BaseModelV1 # type: ignore[assignment]
from pydantic.v1.color import Color # type: ignore[assignment]
from pydantic.v1.fields import DeferredType, ModelField, Undefined
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message=".*Pydantic V1.*", category=UserWarning)
import pydantic.v1 as pydantic_v1 # type: ignore[no-redef]
from pydantic.v1 import BaseModel as BaseModelV1 # type: ignore[assignment]
from pydantic.v1.color import Color # type: ignore[assignment]
from pydantic.v1.fields import DeferredType, ModelField, Undefined


if TYPE_CHECKING:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ lint = [
"pre-commit>=3.4.0",
"shellcheck-py>=0.9.0.5",
"pyright>=1.1.327",
"sourcery>=1.9.0",
]
test = [
"pytest>=7.4.2",
Expand Down
5 changes: 5 additions & 0 deletions tests/test_msgspec_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from polyfactory.exceptions import ParameterException
from polyfactory.factories.msgspec_factory import MsgspecFactory

pytestmark = pytest.mark.skipif(
sys.version_info >= (3, 14),
reason="msgspec not supported on Python 3.14",
)


def test_is_supported_type() -> None:
class Foo(Struct): ...
Expand Down
24 changes: 22 additions & 2 deletions tests/test_pydantic_v1_v2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests to check that usage of pydantic v1 and v2 at the same time works."""

import sys
from typing import Annotated, Optional, Union

import pytest
Expand All @@ -18,16 +19,33 @@
except ImportError:
from pydantic import BaseModel as BaseModelV1 # type: ignore[assignment]

skip_pydantic_v1_on_py314 = pytest.mark.skipif(
sys.version_info >= (3, 14),
reason="pydantic v1 not supported on Python 3.14",
)

@pytest.mark.parametrize("base_model", [BaseModelV1, BaseModelV2])

@pytest.mark.parametrize(
"base_model",
[
pytest.param(BaseModelV1, marks=skip_pydantic_v1_on_py314),
BaseModelV2,
],
)
def test_is_supported_type(base_model: type[Union[BaseModelV1, BaseModelV2]]) -> None:
class Foo(base_model): # type: ignore[valid-type, misc]
...

assert ModelFactory.is_supported_type(Foo) is True


@pytest.mark.parametrize("base_model", [BaseModelV1, BaseModelV2])
@pytest.mark.parametrize(
"base_model",
[
pytest.param(BaseModelV1, marks=skip_pydantic_v1_on_py314),
BaseModelV2,
],
)
def test_build(base_model: type[Union[BaseModelV1, BaseModelV2]]) -> None:
class Foo(base_model): # type: ignore[valid-type, misc]
a: int
Expand All @@ -42,6 +60,7 @@ class Foo(base_model): # type: ignore[valid-type, misc]
assert isinstance(foo.c, bool)


@skip_pydantic_v1_on_py314
def test_build_v1_with_constrained_fields() -> None:
from pydantic.v1.fields import Field

Expand Down Expand Up @@ -91,6 +110,7 @@ class Factory(ModelFactory[Foo]):
assert 7 <= len(result.bar) <= 8


@skip_pydantic_v1_on_py314
def test_build_v1_with_url_and_email_types() -> None:
from pydantic.v1 import AnyHttpUrl, AnyUrl, EmailStr, HttpUrl, NameEmail

Expand Down
Loading
Loading