File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed
src/hypothesis/internal/conjecture Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1+ RELEASE_TYPE: patch
2+
3+ This release fixes a small caching bug in Hypothesis internals that may under
4+ some circumstances have resulted in a less diverse set of test cases being
5+ generated than was intended.
Original file line number Diff line number Diff line change @@ -1033,7 +1033,8 @@ def kill_branch(self):
10331033 )
10341034 self .test_function (data )
10351035 result = check_result (data .as_result ())
1036- self .__data_cache [buffer ] = result
1036+ if extend == 0 or len (result .buffer ) <= len (buffer ):
1037+ self .__data_cache [buffer ] = result
10371038 return result
10381039
10391040 def event_to_string (self , event ):
Original file line number Diff line number Diff line change @@ -1465,3 +1465,34 @@ def test(data):
14651465 except RunIsComplete :
14661466 pass
14671467 assert runner .optimise_targets .call_count == 0
1468+
1469+
1470+ def test_does_not_cache_extended_prefix ():
1471+ def test (data ):
1472+ data .draw_bits (64 )
1473+
1474+ with deterministic_PRNG ():
1475+ runner = ConjectureRunner (test , settings = TEST_SETTINGS )
1476+
1477+ d1 = runner .cached_test_function (b"" , extend = 8 )
1478+ d2 = runner .cached_test_function (b"" , extend = 8 )
1479+ assert d1 .status == d2 .status == Status .VALID
1480+
1481+ assert d1 .buffer != d2 .buffer
1482+
1483+
1484+ def test_does_cache_if_extend_is_not_used ():
1485+ calls = [0 ]
1486+
1487+ def test (data ):
1488+ calls [0 ] += 1
1489+ data .draw_bits (8 )
1490+
1491+ with deterministic_PRNG ():
1492+ runner = ConjectureRunner (test , settings = TEST_SETTINGS )
1493+
1494+ d1 = runner .cached_test_function (b"\0 " , extend = 8 )
1495+ d2 = runner .cached_test_function (b"\0 " , extend = 8 )
1496+ assert d1 .status == d2 .status == Status .VALID
1497+ assert d1 .buffer == d2 .buffer
1498+ assert calls [0 ] == 1
You can’t perform that action at this time.
0 commit comments