From e90c6a725a6d6e4d96c0235e0e73db18a163963b Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Fri, 6 Mar 2026 19:15:27 +0000 Subject: [PATCH] gh-145607: Reproduce flaky test_bz2.testDecompressorChunksMaxsize Sort the glob results then shuffle with a fixed seed (555) so that the first bz2 block's compressed data extends into the last 64 bytes of BIG_DATA. The -64 truncation then yields an incomplete block, causing the assertFalse(bzd.needs_input) assertion to fail. --- Lib/test/test_bz2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py index 3b7897b8a88a45..32ce04b0f90cfe 100644 --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -72,7 +72,9 @@ class BaseTest(unittest.TestCase): # simply use the bigger test data for all tests. test_size = 0 BIG_TEXT = bytearray(128*1024) - for fname in glob.glob(os.path.join(glob.escape(os.path.dirname(__file__)), '*.py')): + _files = sorted(glob.glob(os.path.join(glob.escape(os.path.dirname(__file__)), '*.py'))) + random.Random(555).shuffle(_files) + for fname in _files: with open(fname, 'rb') as fh: test_size += fh.readinto(memoryview(BIG_TEXT)[test_size:]) if test_size > 128*1024: