Skip to content
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
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
import re
import sys
from dataclasses import dataclass
from pathlib import Path
from time import sleep, time
Expand All @@ -17,12 +18,17 @@
from pydantic_core import ArgsKwargs, CoreSchema, SchemaValidator, ValidationError, validate_core_schema
from pydantic_core.core_schema import CoreConfig

__all__ = 'Err', 'PyAndJson', 'plain_repr', 'infinite_generator'
__all__ = 'Err', 'PyAndJson', 'assert_gc', 'is_free_threaded', 'plain_repr', 'infinite_generator'

hypothesis.settings.register_profile('fast', max_examples=2)
hypothesis.settings.register_profile('slow', max_examples=1_000)
hypothesis.settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'fast'))

try:
is_free_threaded = not sys._is_gil_enabled()
except AttributeError:
is_free_threaded = False


def plain_repr(obj):
r = repr(obj)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_garbage_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pydantic_core import SchemaSerializer, SchemaValidator, core_schema

from .conftest import assert_gc
from .conftest import assert_gc, is_free_threaded

GC_TEST_SCHEMA_INNER = core_schema.definitions_schema(
core_schema.definition_reference_schema(schema_ref='model'),
Expand All @@ -20,6 +20,7 @@
)


@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
@pytest.mark.xfail(
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
)
Expand Down Expand Up @@ -47,6 +48,7 @@ class MyModel(BaseModel):
assert_gc(lambda: len(cache) == 0)


@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
@pytest.mark.xfail(
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
)
Expand Down
3 changes: 2 additions & 1 deletion tests/validators/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from pydantic_core import ArgsKwargs, SchemaValidator, ValidationError, core_schema

from ..conftest import Err, PyAndJson, assert_gc
from ..conftest import Err, PyAndJson, assert_gc, is_free_threaded


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1516,6 +1516,7 @@ def test_dataclass_wrap_json():
assert v.validate_json('{"a": "hello", "b": true}', strict=True) == FooDataclass(a='hello', b=True)


@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
@pytest.mark.xfail(
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
)
Expand Down
3 changes: 2 additions & 1 deletion tests/validators/test_model_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pydantic_core import CoreConfig, SchemaValidator, core_schema

from ..conftest import assert_gc
from ..conftest import assert_gc, is_free_threaded


class MyModel:
Expand Down Expand Up @@ -411,6 +411,7 @@ def __init__(self, **kwargs):
assert calls == ["{'a': '1'}", "{'a': '1', 'x': 4}"]


@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
@pytest.mark.xfail(
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
)
Expand Down
3 changes: 2 additions & 1 deletion tests/validators/test_with_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
core_schema,
)

from ..conftest import PyAndJson, assert_gc
from ..conftest import PyAndJson, assert_gc, is_free_threaded


def test_typed_dict_default():
Expand Down Expand Up @@ -636,6 +636,7 @@ def val_func(v: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> Any:
validator.validate_python('')


@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
@pytest.mark.xfail(
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
)
Expand Down
Loading