Skip to content

Commit 2c4cbba

Browse files
Copilotev-br
andcommitted
Fix unvectorized marker for class methods
Co-authored-by: ev-br <2133832+ev-br@users.noreply.github.com>
1 parent d597b5c commit 2c4cbba

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

conftest.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from functools import lru_cache
22
from pathlib import Path
33
import argparse
4+
import inspect
45
import warnings
56
import os
67

@@ -253,9 +254,20 @@ def pytest_collection_modifyitems(config, items):
253254
# reduce max generated Hypothesis example for unvectorized tests
254255
if any(m.name == "unvectorized" for m in markers):
255256
# TODO: limit generated examples when settings already applied
256-
if not hasattr(item.obj, "_hypothesis_internal_settings_applied"):
257+
# For class methods, we need to access the underlying function
258+
test_func = item.obj
259+
if inspect.ismethod(test_func):
260+
test_func = test_func.__func__
261+
262+
if not hasattr(test_func, "_hypothesis_internal_settings_applied"):
257263
try:
258-
item.obj = settings(max_examples=unvectorized_max_examples)(item.obj)
264+
decorated_func = settings(max_examples=unvectorized_max_examples)(test_func)
265+
# For class methods, replace the function in the class
266+
if inspect.ismethod(item.obj):
267+
# Get the class and method name
268+
setattr(item.obj.__self__.__class__, item.obj.__name__, decorated_func)
269+
else:
270+
item.obj = decorated_func
259271
except InvalidArgument as e:
260272
warnings.warn(
261273
f"Tried decorating {item.name} with settings() but got "

0 commit comments

Comments
 (0)