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
54import warnings
65import os
76
@@ -254,18 +253,15 @@ def pytest_collection_modifyitems(config, items):
254253 # reduce max generated Hypothesis example for unvectorized tests
255254 if any (m .name == "unvectorized" for m in markers ):
256255 # TODO: limit generated examples when settings already 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__
261256
257+ # account for both test functions and test methods of test classes
258+ test_func = getattr (item .obj , "__func__" , item .obj )
259+
260+ # https://groups.google.com/g/hypothesis-users/c/6K6WPR5knAs
262261 if not hasattr (test_func , "_hypothesis_internal_settings_applied" ):
263262 try :
264- decorated_func = settings (max_examples = unvectorized_max_examples )(test_func )
265- if inspect .ismethod (item .obj ):
266- setattr (item .cls , item .obj .__name__ , decorated_func )
267- else :
268- item .obj = decorated_func
263+ sett = settings (max_examples = unvectorized_max_examples )
264+ test_func ._hypothesis_internal_use_settings = sett
269265 except InvalidArgument as e :
270266 warnings .warn (
271267 f"Tried decorating { item .name } with settings() but got "
You can’t perform that action at this time.
0 commit comments