Skip to content

Commit 5d5b55a

Browse files
authored
Merge pull request #422 from ev-br/unvectorized_decorator_in_test_classes
MAINT: fix the "unvectorized" pytest mark to work for test methods of test classes This follows the recommendation from https://groups.google.com/g/hypothesis-users/c/6K6WPR5knAs. Previous iterations of this fix (which led to me asking upstream) were helped by Copilot.
2 parents d8e7b2d + de6b2f0 commit 5d5b55a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,15 @@ def pytest_collection_modifyitems(config, items):
253253
# reduce max generated Hypothesis example for unvectorized tests
254254
if any(m.name == "unvectorized" for m in markers):
255255
# TODO: limit generated examples when settings already applied
256-
if not hasattr(item.obj, "_hypothesis_internal_settings_applied"):
256+
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
261+
if not hasattr(test_func, "_hypothesis_internal_settings_applied"):
257262
try:
258-
item.obj = settings(max_examples=unvectorized_max_examples)(item.obj)
263+
sett = settings(max_examples=unvectorized_max_examples)
264+
test_func._hypothesis_internal_use_settings = sett
259265
except InvalidArgument as e:
260266
warnings.warn(
261267
f"Tried decorating {item.name} with settings() but got "

0 commit comments

Comments
 (0)