@@ -2217,19 +2217,37 @@ def wrapped_test(*arguments, **kwargs):
22172217 generated_seed = (
22182218 wrapped_test ._hypothesis_internal_use_generated_seed
22192219 )
2220+ assert state ._runner is not None
2221+ stopped_because_slow_shrinking = (
2222+ state ._runner .statistics .get ("stopped-because" )
2223+ == "shrinking was very slow"
2224+ )
22202225 with local_settings (settings ):
2221- if not (state .failed_normally or generated_seed is None ):
2222- if running_under_pytest :
2223- report (
2224- f"You can add @seed({ generated_seed } ) to this test or "
2225- f"run pytest with --hypothesis-seed={ generated_seed } "
2226- "to reproduce this failure."
2226+ if generated_seed is not None and (
2227+ not state .failed_normally or stopped_because_slow_shrinking
2228+ ):
2229+ pytest_extra_msg = (
2230+ (
2231+ ", or by running pytest with "
2232+ f"--hypothesis-seed={ generated_seed } "
2233+ )
2234+ if running_under_pytest
2235+ else ""
2236+ )
2237+ if stopped_because_slow_shrinking :
2238+ msg = (
2239+ "\n This test function exited early because"
2240+ " it took too long to shrink. If desired for debugging, "
2241+ f"you can reproduce this by adding @seed({ generated_seed } ) "
2242+ f"to this test{ pytest_extra_msg } ."
22272243 )
22282244 else :
2229- report (
2230- f"You can add @seed({ generated_seed } ) to this test to "
2231- "reproduce this failure."
2245+ msg = (
2246+ "You can reproduce this failure by adding "
2247+ f"@seed({ generated_seed } ) to this test"
2248+ f"{ pytest_extra_msg } ."
22322249 )
2250+ report (msg )
22332251 # The dance here is to avoid showing users long tracebacks
22342252 # full of Hypothesis internals they don't care about.
22352253 # We have to do this inline, to avoid adding another
0 commit comments