Skip to content

Commit c0e148c

Browse files
committed
MAINT: use a recommended way to set max_examples for unvectorized tests
Follow the recommendation at https://groups.google.com/g/hypothesis-users/c/6K6WPR5knAs
1 parent 4cc1072 commit c0e148c

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

conftest.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from functools import lru_cache
22
from pathlib import Path
33
import argparse
4-
import inspect
54
import warnings
65
import 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 "

0 commit comments

Comments
 (0)