Skip to content

Commit b3792c3

Browse files
Clean up the panel created by test_userptr_segfault
Unlike the sibling panel tests, test_userptr_segfault never removed its panel, so the window it wrapped was reachable only through a panel<->userptr __del__ cycle and was collected during a much later test, where delwin() failed on macOS (--fail-env-changed). Give it the addCleanup(self._delete_panels, ...) the other panel tests use; the per-test screen.close() in setUp then keeps the teardown free of lingering cycles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6fb6465 commit b3792c3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Lib/test/test_curses.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ def setUp(self):
124124
infd = stdout_fd
125125
self.screen = curses.newterm(term, stdout_fd, infd)
126126
self.stdscr = self.screen.stdscr
127-
# Close the screen after the test: it breaks the window<->screen
128-
# reference cycle and detaches the standard window so its delwin()
129-
# is skipped. Otherwise the window is collected during a later test
130-
# whose screen is no longer current, and delwin() fails (unraisable
131-
# on macOS).
127+
# Close the screen after the test to break its window<->screen
128+
# reference cycle deterministically, rather than leaving it for the
129+
# cyclic GC to collect during a much later test (where a window's
130+
# delwin() can fail -- an unraisable error on macOS).
132131
self.addCleanup(self.screen.close)
133132
self.addCleanup(setattr, self, 'screen', None)
134133
self.addCleanup(setattr, self, 'stdscr', None)
@@ -1196,6 +1195,10 @@ def test_userptr_memory_leak(self):
11961195
def test_userptr_segfault(self):
11971196
w = curses.newwin(10, 10)
11981197
panel = curses.panel.new_panel(w)
1198+
# set_userptr(A()) makes a panel<->userptr reference cycle (A.__del__
1199+
# closes over panel); clean it up so the panel and its window do not
1200+
# linger until a later test collects them.
1201+
self.addCleanup(self._delete_panels, panel)
11991202
class A:
12001203
def __del__(self):
12011204
panel.set_userptr(None)

0 commit comments

Comments
 (0)