diff --git a/noxfile.py b/noxfile.py index 486c191e89..6630690efe 100644 --- a/noxfile.py +++ b/noxfile.py @@ -23,6 +23,8 @@ def tests(session: Session) -> None: "not django", "-m", "not starlite", + "-m", + "not pydantic", "--ignore=tests/mypy", "--ignore=tests/pyright", ) @@ -88,6 +90,28 @@ def tests_litestar(session: Session) -> None: ) +@session(python=["3.11"], name="Pydantic tests", tags=["tests"]) +# TODO: add pydantic 2.0 here :) +@nox.parametrize("pydantic", ["1.10"]) +def test_pydantic(session: Session, pydantic: str) -> None: + session.run_always("poetry", "install", external=True) + + session._session.install(f"pydantic~={pydantic}") # type: ignore + + session.run( + "pytest", + "--cov=strawberry", + "--cov-append", + "--cov-report=xml", + "-n", + "auto", + "--showlocals", + "-vv", + "-m", + "pydantic", + ) + + @session(python=PYTHON_VERSIONS, name="Mypy tests") def tests_mypy(session: Session) -> None: session.run_always("poetry", "install", external=True) diff --git a/pyproject.toml b/pyproject.toml index 378834907b..3ee8c50161 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -159,6 +159,7 @@ markers = [ "chalice", "flask", "starlite", + "pydantic", "flaky", "relay", ] diff --git a/tests/conftest.py b/tests/conftest.py index d022cbd6f0..8be7f83d35 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,12 +1,26 @@ -from typing import Tuple +import pathlib +from typing import List, Tuple +import pytest -def pytest_emoji_xfailed(config) -> Tuple[str, str]: + +def pytest_emoji_xfailed(config: pytest.Config) -> Tuple[str, str]: return "🤷‍♂️ ", "XFAIL 🤷‍♂️ " -def pytest_emoji_skipped(config) -> Tuple[str, str]: +def pytest_emoji_skipped(config: pytest.Config) -> Tuple[str, str]: return "🦘 ", "SKIPPED 🦘" pytest_plugins = ("tests.plugins.strawberry_exceptions",) + + +@pytest.hookimpl # type: ignore +def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item]): + rootdir = pathlib.Path(config.rootdir) # type: ignore + + for item in items: + rel_path = pathlib.Path(item.fspath).relative_to(rootdir) + + if "pydantic" in rel_path.parts: + item.add_marker(pytest.mark.pydantic) diff --git a/tests/schema/test_pydantic.py b/tests/schema/test_pydantic.py index f4dc07551a..793862429b 100644 --- a/tests/schema/test_pydantic.py +++ b/tests/schema/test_pydantic.py @@ -1,7 +1,10 @@ +import pytest from pydantic import BaseModel, Field import strawberry +pytestmark = pytest.mark.pydantic + def test_use_alias_as_gql_name(): class UserModel(BaseModel):