Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_io/test_textio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import threading
import time
import tracemalloc
import unittest
import warnings
import weakref
Expand Down Expand Up @@ -1522,6 +1523,21 @@ def write(self, data):
t.write("x"*chunk_size)
self.assertEqual([b"abcdef", b"ghi", b"x"*chunk_size], buf._write_stack)

def test_write_empty_no_memory_growth(self):
# gh-151814: Writing empty string should have stable memory usage.
t = self.TextIOWrapper(self.BytesIO())
nwrites = 200_000
tracemalloc.start()
try:
for _ in range(nwrites):
t.write("")
_, peak = tracemalloc.get_traced_memory()
finally:
tracemalloc.stop()

# No longer leaks several bytes per write.
self.assertLess(peak, nwrites)

def test_issue119506(self):
chunk_size = 8192

Expand Down
Loading