From de6b2f0c6bd5f089f0fd71f8a3a11b6e220173a2 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Mon, 9 Feb 2026 17:04:11 +0100 Subject: [PATCH] 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. --- conftest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/conftest.py b/conftest.py index dc50c9ae..f7d2d96e 100644 --- a/conftest.py +++ b/conftest.py @@ -253,9 +253,15 @@ def pytest_collection_modifyitems(config, items): # reduce max generated Hypothesis example for unvectorized tests if any(m.name == "unvectorized" for m in markers): # TODO: limit generated examples when settings already applied - if not hasattr(item.obj, "_hypothesis_internal_settings_applied"): + + # account for both test functions and test methods of test classes + test_func = getattr(item.obj, "__func__", item.obj) + + # https://groups.google.com/g/hypothesis-users/c/6K6WPR5knAs + if not hasattr(test_func, "_hypothesis_internal_settings_applied"): try: - item.obj = settings(max_examples=unvectorized_max_examples)(item.obj) + sett = settings(max_examples=unvectorized_max_examples) + test_func._hypothesis_internal_use_settings = sett except InvalidArgument as e: warnings.warn( f"Tried decorating {item.name} with settings() but got "