More useful error message for flaky test failure

This commit is contained in:
Kovid Goyal 2026-10-26 06:50:34 +05:30
parent db9ae83672
commit 6815b7a8a4
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -11,13 +11,26 @@ from kitty.constants import is_macos, kitty_exe
from .base import BaseTest
def spawn_and_wait_for_ready(code: str, what: str) -> subprocess.Popen:
# Run code via kitty +runpy and wait for it to print ready. stderr is
# captured, as in test workers it is /dev/null, so that the reason the
# child failed is reported.
p = subprocess.Popen([kitty_exe(), '+runpy', code], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
line = p.stdout.readline().strip()
p.stdout.close()
if line != b'ready':
p.kill()
err = p.stderr.read().decode('utf-8', 'replace')
p.stderr.close()
raise AssertionError(f'Unexpected output from {what}: {line!r} exit code: {p.wait()} stderr:\n{err}')
p.stderr.close()
return p
class ChildMemoryTest(BaseTest):
def _spawn_allocating_child(self, alloc_bytes: int) -> subprocess.Popen:
p = subprocess.Popen(
[
kitty_exe(),
'+runpy',
f"""\
return spawn_and_wait_for_ready(
f"""\
import sys, time
buf = bytearray({alloc_bytes})
for i in range(0, {alloc_bytes}, 4096):
@ -26,16 +39,8 @@ sys.stdout.write("ready\\n")
sys.stdout.flush()
time.sleep(300)
""",
],
stdout=subprocess.PIPE,
'allocating child',
)
line = p.stdout.readline().strip()
p.stdout.close()
if line != b'ready':
p.kill()
p.wait()
raise AssertionError(f'Unexpected output from allocating child: {line!r}')
return p
def _terminate(self, p: subprocess.Popen) -> None:
p.terminate()
@ -128,14 +133,7 @@ sys.stdout.write("ready\\n")
sys.stdout.flush()
time.sleep(300)
"""
p = subprocess.Popen([kitty_exe(), '+runpy', code], stdout=subprocess.PIPE)
line = p.stdout.readline().strip()
p.stdout.close()
if line != b'ready':
p.kill()
p.wait()
raise AssertionError(f'Unexpected output from wrapper: {line!r}')
return p
return spawn_and_wait_for_ready(code, 'wrapper')
def _terminate_tree(self, p: subprocess.Popen) -> None:
children = children_of_process(p.pid)