[{"data":1,"prerenderedAt":724},["ShallowReactive",2],{"page-\u002Fproperty-based-fuzz-testing-strategies\u002Fhypothesis-framework-fundamentals\u002Ffixing-hypothesis-flaky-health-check-failures\u002F":3},{"id":4,"title":5,"body":6,"description":704,"extension":705,"meta":706,"navigation":145,"path":720,"seo":721,"stem":722,"__hash__":723},"content\u002Fproperty-based-fuzz-testing-strategies\u002Fhypothesis-framework-fundamentals\u002Ffixing-hypothesis-flaky-health-check-failures\u002Findex.md","Fixing Hypothesis FlakyHealthCheck Failures",{"type":7,"value":8,"toc":697},"minimark",[9,38,43,89,93,100,123,131,228,246,261,309,316,364,378,531,535,551,555,631,635,656,672,688,693],[10,11,12,13,17,18,21,22,21,25,28,29,32,33,37],"p",{},"Your Hypothesis test fails not with a falsifying example but with ",[14,15,16],"code",{},"hypothesis.errors.FailedHealthCheck"," — ",[14,19,20],{},"too_slow",", ",[14,23,24],{},"filter_too_much",[14,26,27],{},"data_too_large",", or the ",[14,30,31],{},"function_scoped_fixture"," warning. These are not bugs in your code under test; they are guardrails telling you the ",[34,35,36],"em",{},"test harness"," is degenerate: generation is too slow, too many examples are being thrown away, generated data is enormous, or a fixture is silently shared across examples. This guide explains each check and the correct fix, versus the blunt suppress-everything anti-pattern.",[39,40,42],"h2",{"id":41},"prerequisites","Prerequisites",[44,45,46,64,70],"ul",{},[47,48,49,52,53,56,57,60,61,63],"li",{},[14,50,51],{},"hypothesis >= 6.0"," (the ",[14,54,55],{},"HealthCheck"," enum and ",[14,58,59],{},"suppress_health_check"," settings argument are stable across 6.x; ",[14,62,31],{}," was added in 5.x)",[47,65,66,69],{},[14,67,68],{},"pytest >= 7.0",", Python 3.9+",[47,71,72,73,21,76,21,79,82,83,88],{},"Familiarity with ",[14,74,75],{},"@given",[14,77,78],{},"@settings",[14,80,81],{},"assume",", and strategy filtering from ",[84,85,87],"a",{"href":86},"\u002Fproperty-based-fuzz-testing-strategies\u002Fhypothesis-framework-fundamentals\u002F","Hypothesis Framework Fundamentals",".",[39,90,92],{"id":91},"solution","Solution",[10,94,95,96,99],{},"Each health check has a distinct trigger and a distinct correct fix. Import the enum from ",[14,97,98],{},"hypothesis",":",[101,102,107],"pre",{"className":103,"code":104,"language":105,"meta":106,"style":106},"language-python shiki shiki-themes github-light github-dark","from hypothesis import given, settings, HealthCheck, assume\nimport hypothesis.strategies as st\n","python","",[14,108,109,117],{"__ignoreMap":106},[110,111,114],"span",{"class":112,"line":113},"line",1,[110,115,116],{},"from hypothesis import given, settings, HealthCheck, assume\n",[110,118,120],{"class":112,"line":119},2,[110,121,122],{},"import hypothesis.strategies as st\n",[10,124,125,130],{},[126,127,128],"strong",{},[14,129,20],{}," — Hypothesis aborts because it spent too long generating examples relative to running them. The fix is rarely suppression; usually the strategy is doing expensive work per example or the deadline is misread.",[101,132,134],{"className":103,"code":133,"language":105,"meta":106,"style":106},"import time\n\n# WRONG: hides a real slowness signal\n@settings(suppress_health_check=[HealthCheck.too_slow])\n@given(st.integers())\ndef test_blunt(n):\n    time.sleep(0.05)  # genuinely slow body — suppression masks it\n    assert n == n\n\n# RIGHT: if the body is legitimately slow (real I\u002FO), raise the deadline\n# AND suppress only too_slow, having confirmed the cost is intrinsic.\n@settings(deadline=None, suppress_health_check=[HealthCheck.too_slow])\n@given(st.integers())\ndef test_legit_slow_io(n):\n    time.sleep(0.05)   # e.g. an unavoidable network round-trip\n    assert n == n\n",[14,135,136,141,147,153,159,165,171,177,183,188,194,200,206,211,217,223],{"__ignoreMap":106},[110,137,138],{"class":112,"line":113},[110,139,140],{},"import time\n",[110,142,143],{"class":112,"line":119},[110,144,146],{"emptyLinePlaceholder":145},true,"\n",[110,148,150],{"class":112,"line":149},3,[110,151,152],{},"# WRONG: hides a real slowness signal\n",[110,154,156],{"class":112,"line":155},4,[110,157,158],{},"@settings(suppress_health_check=[HealthCheck.too_slow])\n",[110,160,162],{"class":112,"line":161},5,[110,163,164],{},"@given(st.integers())\n",[110,166,168],{"class":112,"line":167},6,[110,169,170],{},"def test_blunt(n):\n",[110,172,174],{"class":112,"line":173},7,[110,175,176],{},"    time.sleep(0.05)  # genuinely slow body — suppression masks it\n",[110,178,180],{"class":112,"line":179},8,[110,181,182],{},"    assert n == n\n",[110,184,186],{"class":112,"line":185},9,[110,187,146],{"emptyLinePlaceholder":145},[110,189,191],{"class":112,"line":190},10,[110,192,193],{},"# RIGHT: if the body is legitimately slow (real I\u002FO), raise the deadline\n",[110,195,197],{"class":112,"line":196},11,[110,198,199],{},"# AND suppress only too_slow, having confirmed the cost is intrinsic.\n",[110,201,203],{"class":112,"line":202},12,[110,204,205],{},"@settings(deadline=None, suppress_health_check=[HealthCheck.too_slow])\n",[110,207,209],{"class":112,"line":208},13,[110,210,164],{},[110,212,214],{"class":112,"line":213},14,[110,215,216],{},"def test_legit_slow_io(n):\n",[110,218,220],{"class":112,"line":219},15,[110,221,222],{},"    time.sleep(0.05)   # e.g. an unavoidable network round-trip\n",[110,224,226],{"class":112,"line":225},16,[110,227,182],{},[10,229,230,231,234,235,238,239,234,242,245],{},"Note the distinction: ",[14,232,233],{},"deadline=None"," disables the ",[34,236,237],{},"per-example"," timing assertion, while ",[14,240,241],{},"suppress_health_check=[HealthCheck.too_slow]",[34,243,244],{},"aggregate"," generation-time guard. They are separate; slow tests often need both, but only after confirming the cost is real.",[10,247,248,252,253,256,257,260],{},[126,249,250],{},[14,251,24],{}," — Hypothesis discarded too many generated examples because a ",[14,254,255],{},".filter()"," predicate or ",[14,258,259],{},"assume()"," rejects most candidates. Suppressing it does not help; the generator is starving. Constrain the strategy at its source instead.",[101,262,264],{"className":103,"code":263,"language":105,"meta":106,"style":106},"# WRONG: filter rejects ~99% of integers, starving the generator\n@given(st.integers().filter(lambda x: 1000 \u003C= x \u003C= 1005))\ndef test_starved(x):\n    assert 1000 \u003C= x \u003C= 1005\n\n# RIGHT: generate inside the constraint so nothing is discarded\n@given(st.integers(min_value=1000, max_value=1005))\ndef test_bounded(x):\n    assert 1000 \u003C= x \u003C= 1005\n",[14,265,266,271,276,281,286,290,295,300,305],{"__ignoreMap":106},[110,267,268],{"class":112,"line":113},[110,269,270],{},"# WRONG: filter rejects ~99% of integers, starving the generator\n",[110,272,273],{"class":112,"line":119},[110,274,275],{},"@given(st.integers().filter(lambda x: 1000 \u003C= x \u003C= 1005))\n",[110,277,278],{"class":112,"line":149},[110,279,280],{},"def test_starved(x):\n",[110,282,283],{"class":112,"line":155},[110,284,285],{},"    assert 1000 \u003C= x \u003C= 1005\n",[110,287,288],{"class":112,"line":161},[110,289,146],{"emptyLinePlaceholder":145},[110,291,292],{"class":112,"line":167},[110,293,294],{},"# RIGHT: generate inside the constraint so nothing is discarded\n",[110,296,297],{"class":112,"line":173},[110,298,299],{},"@given(st.integers(min_value=1000, max_value=1005))\n",[110,301,302],{"class":112,"line":179},[110,303,304],{},"def test_bounded(x):\n",[110,306,307],{"class":112,"line":185},[110,308,285],{},[10,310,311,315],{},[126,312,313],{},[14,314,27],{}," — generated examples exceed Hypothesis's internal byte budget, typically from unbounded collections or recursion. Bound the sizes.",[101,317,319],{"className":103,"code":318,"language":105,"meta":106,"style":106},"# WRONG: unbounded nested data routinely exceeds the buffer\n@given(st.lists(st.lists(st.integers())))\ndef test_huge(data):\n    assert isinstance(data, list)\n\n# RIGHT: cap element and collection sizes\n@given(st.lists(st.lists(st.integers(), max_size=20), max_size=20))\ndef test_bounded_size(data):\n    assert isinstance(data, list)\n",[14,320,321,326,331,336,341,345,350,355,360],{"__ignoreMap":106},[110,322,323],{"class":112,"line":113},[110,324,325],{},"# WRONG: unbounded nested data routinely exceeds the buffer\n",[110,327,328],{"class":112,"line":119},[110,329,330],{},"@given(st.lists(st.lists(st.integers())))\n",[110,332,333],{"class":112,"line":149},[110,334,335],{},"def test_huge(data):\n",[110,337,338],{"class":112,"line":155},[110,339,340],{},"    assert isinstance(data, list)\n",[110,342,343],{"class":112,"line":161},[110,344,146],{"emptyLinePlaceholder":145},[110,346,347],{"class":112,"line":167},[110,348,349],{},"# RIGHT: cap element and collection sizes\n",[110,351,352],{"class":112,"line":173},[110,353,354],{},"@given(st.lists(st.lists(st.integers(), max_size=20), max_size=20))\n",[110,356,357],{"class":112,"line":179},[110,358,359],{},"def test_bounded_size(data):\n",[110,361,362],{"class":112,"line":185},[110,363,340],{},[10,365,366,370,371,373,374,377],{},[126,367,368],{},[14,369,31],{}," — a function-scoped pytest fixture is requested by a ",[14,372,75],{}," test. The fixture is set up once for the whole function, but the body runs once per example, so the fixture is ",[34,375,376],{},"not"," reset between examples. This is the most common cause of \"Hypothesis test passes alone, fails in a suite\" flakiness.",[101,379,381],{"className":103,"code":380,"language":105,"meta":106,"style":106},"import pytest\n\n# WRONG: function-scoped, mutable, shared across all examples\n@pytest.fixture\ndef buffer():\n    return []  # one list reused for every generated example\n\n@given(st.integers())\ndef test_leaky(buffer, n):     # raises HealthCheck.function_scoped_fixture\n    buffer.append(n)\n    assert len(buffer) == 1    # FAILS after the first example\n\n# RIGHT (option A): build the per-example resource inside the test body\n@given(st.integers())\ndef test_local_state(n):\n    buffer = []                # fresh each example\n    buffer.append(n)\n    assert len(buffer) == 1\n\n# RIGHT (option B): if the fixture is genuinely set-up-once and read-only\n# (e.g. a connection pool), keep it and suppress only this check.\n@pytest.fixture\ndef readonly_engine():\n    return {\"url\": \"sqlite:\u002F\u002F\"}  # never mutated by the test\n\n@settings(suppress_health_check=[HealthCheck.function_scoped_fixture])\n@given(st.integers())\ndef test_readonly(readonly_engine, n):\n    assert readonly_engine[\"url\"].startswith(\"sqlite\")\n",[14,382,383,388,392,397,402,407,412,416,420,425,430,435,439,444,448,453,458,463,469,474,480,486,491,497,503,508,514,519,525],{"__ignoreMap":106},[110,384,385],{"class":112,"line":113},[110,386,387],{},"import pytest\n",[110,389,390],{"class":112,"line":119},[110,391,146],{"emptyLinePlaceholder":145},[110,393,394],{"class":112,"line":149},[110,395,396],{},"# WRONG: function-scoped, mutable, shared across all examples\n",[110,398,399],{"class":112,"line":155},[110,400,401],{},"@pytest.fixture\n",[110,403,404],{"class":112,"line":161},[110,405,406],{},"def buffer():\n",[110,408,409],{"class":112,"line":167},[110,410,411],{},"    return []  # one list reused for every generated example\n",[110,413,414],{"class":112,"line":173},[110,415,146],{"emptyLinePlaceholder":145},[110,417,418],{"class":112,"line":179},[110,419,164],{},[110,421,422],{"class":112,"line":185},[110,423,424],{},"def test_leaky(buffer, n):     # raises HealthCheck.function_scoped_fixture\n",[110,426,427],{"class":112,"line":190},[110,428,429],{},"    buffer.append(n)\n",[110,431,432],{"class":112,"line":196},[110,433,434],{},"    assert len(buffer) == 1    # FAILS after the first example\n",[110,436,437],{"class":112,"line":202},[110,438,146],{"emptyLinePlaceholder":145},[110,440,441],{"class":112,"line":208},[110,442,443],{},"# RIGHT (option A): build the per-example resource inside the test body\n",[110,445,446],{"class":112,"line":213},[110,447,164],{},[110,449,450],{"class":112,"line":219},[110,451,452],{},"def test_local_state(n):\n",[110,454,455],{"class":112,"line":225},[110,456,457],{},"    buffer = []                # fresh each example\n",[110,459,461],{"class":112,"line":460},17,[110,462,429],{},[110,464,466],{"class":112,"line":465},18,[110,467,468],{},"    assert len(buffer) == 1\n",[110,470,472],{"class":112,"line":471},19,[110,473,146],{"emptyLinePlaceholder":145},[110,475,477],{"class":112,"line":476},20,[110,478,479],{},"# RIGHT (option B): if the fixture is genuinely set-up-once and read-only\n",[110,481,483],{"class":112,"line":482},21,[110,484,485],{},"# (e.g. a connection pool), keep it and suppress only this check.\n",[110,487,489],{"class":112,"line":488},22,[110,490,401],{},[110,492,494],{"class":112,"line":493},23,[110,495,496],{},"def readonly_engine():\n",[110,498,500],{"class":112,"line":499},24,[110,501,502],{},"    return {\"url\": \"sqlite:\u002F\u002F\"}  # never mutated by the test\n",[110,504,506],{"class":112,"line":505},25,[110,507,146],{"emptyLinePlaceholder":145},[110,509,511],{"class":112,"line":510},26,[110,512,513],{},"@settings(suppress_health_check=[HealthCheck.function_scoped_fixture])\n",[110,515,517],{"class":112,"line":516},27,[110,518,164],{},[110,520,522],{"class":112,"line":521},28,[110,523,524],{},"def test_readonly(readonly_engine, n):\n",[110,526,528],{"class":112,"line":527},29,[110,529,530],{},"    assert readonly_engine[\"url\"].startswith(\"sqlite\")\n",[39,532,534],{"id":533},"why-this-works","Why this works",[10,536,537,538,541,542,544,545,547,548,550],{},"Health checks measure properties of the test ",[34,539,540],{},"harness",", not the system under test, so the durable fix changes the harness — bound the strategy, generate within constraints, or stop sharing mutable state — rather than silencing the signal. ",[14,543,59],{}," takes a list of specific ",[14,546,55],{}," members precisely so you can disable one diagnostic you have understood while leaving the rest active. Suppressing ",[14,549,31],{}," is only safe when the fixture is set up once and never mutated, because Hypothesis cannot otherwise guarantee example independence.",[39,552,554],{"id":553},"edge-cases-and-failure-modes","Edge cases and failure modes",[44,556,557,570,579,587,608,621],{},[47,558,559,566,567,569],{},[126,560,561,563,564,88],{},[14,562,233],{}," does not silence ",[14,565,20],{}," They are independent settings; a slow generation phase still trips ",[14,568,20],{}," even with the deadline disabled.",[47,571,572,578],{},[126,573,574,575,577],{},"Suppressing ",[14,576,24],{}," hides a starving generator."," The test will still run, but on a biased, tiny slice of the input space, weakening coverage silently.",[47,580,581,586],{},[126,582,583,584],{},"Session\u002Fmodule-scoped fixtures do not raise ",[14,585,31],{}," — only function scope does. Promoting a read-only fixture's scope is a legitimate fix.",[47,588,589,592,593,595,596,599,600,603,604,88],{},[126,590,591],{},"Stateful machines have their own timing."," ",[14,594,20],{}," on a ",[14,597,598],{},"RuleBasedStateMachine"," usually means real I\u002FO per rule; lower ",[14,601,602],{},"stateful_step_count"," rather than suppressing blindly. See ",[84,605,607],{"href":606},"\u002Fproperty-based-fuzz-testing-strategies\u002Fstateful-and-model-based-testing\u002F","Stateful and Model-Based Testing",[47,609,610,613,614,616,617,88],{},[126,611,612],{},"CI-only failures."," Slower runners trip ",[14,615,20],{}," even when local runs pass; profile and cache before suppressing, per ",[84,618,620],{"href":619},"\u002Fproperty-based-fuzz-testing-strategies\u002Fhypothesis-framework-fundamentals\u002Freducing-hypothesis-test-execution-time\u002F","reducing Hypothesis test execution time",[47,622,623,626,627,88],{},[126,624,625],{},"Async tests."," Function-scoped async fixtures combine both this check and event-loop scoping concerns; the trade-offs are covered in ",[84,628,630],{"href":629},"\u002Fadvanced-pytest-architecture-configuration\u002Fmastering-pytest-fixtures\u002Fpytest-asyncio-vs-anyio-scoping-trade-offs\u002F","pytest-asyncio vs anyio: Scoping Trade-offs",[39,632,634],{"id":633},"frequently-asked-questions","Frequently Asked Questions",[10,636,637,643,644,646,647,649,650,652,653,655],{},[126,638,639,640,642],{},"Should I just set ",[14,641,233],{}," to silence Hypothesis health checks?","\nNo. ",[14,645,233],{}," only disables the per-example timing deadline; it does not suppress the ",[14,648,20],{}," health check, which measures aggregate generation time. Use ",[14,651,59],{}," for the specific check and reserve ",[14,654,233],{}," for operations that are legitimately slow.",[10,657,658,664,665,667,668,671],{},[126,659,660,661,663],{},"Why does Hypothesis warn about function-scoped fixtures with ",[14,662,75],{},"?","\nA function-scoped pytest fixture is set up once for the test function, but ",[14,666,75],{}," runs the body many times, so the fixture is not reset between examples. Hypothesis raises ",[14,669,670],{},"HealthCheck.function_scoped_fixture"," because shared mutable state across examples causes order-dependent flakiness.",[10,673,674,677,678,680,681,683,684,687],{},[126,675,676],{},"How do I suppress a single Hypothesis health check without disabling the rest?","\nPass a list of specific ",[14,679,55],{}," members to ",[14,682,59],{},", e.g. ",[14,685,686],{},"@settings(suppress_health_check=[HealthCheck.too_slow])",". Every other health check stays active.",[10,689,690,691],{},"← Back to ",[84,692,87],{"href":86},[694,695,696],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":106,"searchDepth":119,"depth":119,"links":698},[699,700,701,702,703],{"id":41,"depth":119,"text":42},{"id":91,"depth":119,"text":92},{"id":533,"depth":119,"text":534},{"id":553,"depth":119,"text":554},{"id":633,"depth":119,"text":634},"Resolve Hypothesis FailedHealthCheck errors — too_slow, filter_too_much, data_too_large, function_scoped_fixture — with suppress_health_check, deadline, and fixture fixes.","md",{"slug":707,"type":708,"breadcrumb":709,"datePublished":710,"dateModified":710,"faq":711},"fixing-hypothesis-flaky-health-check-failures","long_tail","FlakyHealthCheck","2026-06-18",[712,715,718],{"q":713,"a":714},"Should I just set deadline=None to silence Hypothesis health checks?","deadline=None only disables the per-example timing deadline; it does not suppress the too_slow health check, which measures aggregate generation time. Use suppress_health_check for the specific check and deadline=None only when the operation is legitimately slow.",{"q":716,"a":717},"Why does Hypothesis warn about function-scoped fixtures with @given?","A function-scoped pytest fixture is set up once for the test function, but @given runs the body many times, so the fixture is not reset between examples. Hypothesis raises HealthCheck.function_scoped_fixture because shared mutable state across examples causes order-dependent flakiness.",{"q":676,"a":719},"Pass a list of specific HealthCheck members to suppress_health_check on the settings decorator, e.g. @settings(suppress_health_check=[HealthCheck.too_slow]). This leaves every other health check active.","\u002Fproperty-based-fuzz-testing-strategies\u002Fhypothesis-framework-fundamentals\u002Ffixing-hypothesis-flaky-health-check-failures",{"title":5,"description":704},"property-based-fuzz-testing-strategies\u002Fhypothesis-framework-fundamentals\u002Ffixing-hypothesis-flaky-health-check-failures\u002Findex","RF1HuqOAJycnqOOrOLsDxV5WT5E-0USMUBNENtllzpw",1781793487860]