Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pydantic tests via nox #2935

Merged
merged 1 commit into from
Jul 8, 2023
Merged
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
24 changes: 24 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def tests(session: Session) -> None:
"not django",
"-m",
"not starlite",
"-m",
"not pydantic",
"--ignore=tests/mypy",
"--ignore=tests/pyright",
)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ markers = [
"chalice",
"flask",
"starlite",
"pydantic",
"flaky",
"relay",
]
Expand Down
20 changes: 17 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions tests/schema/test_pydantic.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down