Skip to content

Commit 5bb2d62

Browse files
authored
Mark some tests as xfailing on free-threaded (#1697)
1 parent 2bcce9f commit 5bb2d62

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

tests/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import os
88
import re
9+
import sys
910
from dataclasses import dataclass
1011
from pathlib import Path
1112
from time import sleep, time
@@ -17,12 +18,17 @@
1718
from pydantic_core import ArgsKwargs, CoreSchema, SchemaValidator, ValidationError, validate_core_schema
1819
from pydantic_core.core_schema import CoreConfig
1920

20-
__all__ = 'Err', 'PyAndJson', 'plain_repr', 'infinite_generator'
21+
__all__ = 'Err', 'PyAndJson', 'assert_gc', 'is_free_threaded', 'plain_repr', 'infinite_generator'
2122

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

27+
try:
28+
is_free_threaded = not sys._is_gil_enabled()
29+
except AttributeError:
30+
is_free_threaded = False
31+
2632

2733
def plain_repr(obj):
2834
r = repr(obj)

tests/test_garbage_collection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pydantic_core import SchemaSerializer, SchemaValidator, core_schema
99

10-
from .conftest import assert_gc
10+
from .conftest import assert_gc, is_free_threaded
1111

1212
GC_TEST_SCHEMA_INNER = core_schema.definitions_schema(
1313
core_schema.definition_reference_schema(schema_ref='model'),
@@ -20,6 +20,7 @@
2020
)
2121

2222

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

4950

51+
@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
5052
@pytest.mark.xfail(
5153
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
5254
)

tests/validators/test_dataclasses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from pydantic_core import ArgsKwargs, SchemaValidator, ValidationError, core_schema
1212

13-
from ..conftest import Err, PyAndJson, assert_gc
13+
from ..conftest import Err, PyAndJson, assert_gc, is_free_threaded
1414

1515

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

15181518

1519+
@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
15191520
@pytest.mark.xfail(
15201521
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
15211522
)

tests/validators/test_model_init.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from pydantic_core import CoreConfig, SchemaValidator, core_schema
88

9-
from ..conftest import assert_gc
9+
from ..conftest import assert_gc, is_free_threaded
1010

1111

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

413413

414+
@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
414415
@pytest.mark.xfail(
415416
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
416417
)

tests/validators/test_with_default.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
core_schema,
1717
)
1818

19-
from ..conftest import PyAndJson, assert_gc
19+
from ..conftest import PyAndJson, assert_gc, is_free_threaded
2020

2121

2222
def test_typed_dict_default():
@@ -636,6 +636,7 @@ def val_func(v: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> Any:
636636
validator.validate_python('')
637637

638638

639+
@pytest.mark.xfail(is_free_threaded, reason='GC leaks on free-threaded')
639640
@pytest.mark.xfail(
640641
condition=platform.python_implementation() == 'PyPy', reason='https://foss.heptapod.net/pypy/pypy/-/issues/3899'
641642
)

0 commit comments

Comments
 (0)