Skip to content

Commit 0c53091

Browse files
committed
fix pypy tests on windows
1 parent 0b31711 commit 0c53091

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/recursion_guard.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ pub struct RecursionGuard {
2020
}
2121

2222
// A hard limit to avoid stack overflows when rampant recursion occurs
23-
pub const RECURSION_GUARD_LIMIT: u16 = if cfg!(target_family = "wasm") { 50 } else { 255 };
23+
pub const RECURSION_GUARD_LIMIT: u16 = if cfg!(target_family = "wasm") || cfg!(all(target_os = "windows", PyPy)) {
24+
50
25+
} else {
26+
255
27+
};
2428

2529
impl RecursionGuard {
2630
// insert a new id into the set, return whether the set already had the id in it

tests/benchmarks/test_micro_benchmarks.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Numerous benchmarks of specific functionality.
33
"""
44
import json
5-
import platform
6-
import sys
75
from datetime import date, datetime, timedelta, timezone
86
from decimal import Decimal
97
from enum import Enum
@@ -16,15 +14,6 @@
1614
from pydantic_core import ArgsKwargs, PydanticCustomError, SchemaValidator, ValidationError, core_schema
1715
from pydantic_core import ValidationError as CoreValidationError
1816

19-
skip_pypy_deep_stack = pytest.mark.skipif(
20-
platform.python_implementation() == 'PyPy' and pydantic_core._pydantic_core.build_profile == 'debug',
21-
reason='PyPy does not have enough stack space for Rust debug builds to recurse very deep',
22-
)
23-
24-
skip_wasm_deep_stack = pytest.mark.skipif(
25-
sys.platform == 'emscripten', reason='wasm does not have enough stack space to recurse very deep'
26-
)
27-
2817

2918
class TestBenchmarkSimpleModel:
3019
@pytest.fixture(scope='class')
@@ -274,14 +263,12 @@ def definition_model_data():
274263
data = {'width': -1}
275264

276265
_data = data
277-
for i in range(100):
266+
for i in range(pydantic_core._pydantic_core._recursion_limit - 2):
278267
_data['branch'] = {'width': i}
279268
_data = _data['branch']
280269
return data
281270

282271

283-
@skip_pypy_deep_stack
284-
@skip_wasm_deep_stack
285272
@pytest.mark.benchmark(group='recursive model')
286273
def test_definition_model_core(definition_model_data, benchmark):
287274
class CoreBranch:
@@ -1180,23 +1167,22 @@ def test_tagged_union_int_keys_json(benchmark):
11801167
benchmark(v.validate_json, payload)
11811168

11821169

1183-
@skip_pypy_deep_stack
1184-
@skip_wasm_deep_stack
11851170
@pytest.mark.benchmark(group='field_function_validator')
11861171
def test_field_function_validator(benchmark) -> None:
11871172
def f(v: int, info: core_schema.FieldValidationInfo) -> int:
11881173
assert info.field_name == 'x'
11891174
return v + 1
11901175

11911176
schema: core_schema.CoreSchema = core_schema.int_schema()
1177+
limit = pydantic_core._pydantic_core._recursion_limit - 3
11921178

1193-
for _ in range(100):
1179+
for _ in range(limit):
11941180
schema = core_schema.field_after_validator_function(f, 'x', schema)
11951181

11961182
schema = core_schema.typed_dict_schema({'x': core_schema.typed_dict_field(schema)})
11971183

11981184
v = SchemaValidator(schema)
11991185
payload = {'x': 0}
1200-
assert v.validate_python(payload) == {'x': 100}
1186+
assert v.validate_python(payload) == {'x': limit}
12011187

12021188
benchmark(v.validate_python, payload)

0 commit comments

Comments
 (0)