diff --git a/tests/conftest.py b/tests/conftest.py index 226ace018..e9079c8ba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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) diff --git a/tests/test_garbage_collection.py b/tests/test_garbage_collection.py index 2213f7cfb..c129c0e34 100644 --- a/tests/test_garbage_collection.py +++ b/tests/test_garbage_collection.py @@ -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'), @@ -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' ) @@ -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' ) diff --git a/tests/validators/test_dataclasses.py b/tests/validators/test_dataclasses.py index 6ae9f54f9..da4105a55 100644 --- a/tests/validators/test_dataclasses.py +++ b/tests/validators/test_dataclasses.py @@ -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( @@ -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' ) diff --git a/tests/validators/test_model_init.py b/tests/validators/test_model_init.py index 463a9a48a..ccc427800 100644 --- a/tests/validators/test_model_init.py +++ b/tests/validators/test_model_init.py @@ -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: @@ -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' ) diff --git a/tests/validators/test_with_default.py b/tests/validators/test_with_default.py index 2b092d066..ca9b5802d 100644 --- a/tests/validators/test_with_default.py +++ b/tests/validators/test_with_default.py @@ -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(): @@ -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' )