File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from functools import lru_cache
22from pathlib import Path
33import argparse
4+ import inspect
45import warnings
56import 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 "
You can’t perform that action at this time.
0 commit comments