Skip to content

Commit 03f0d8c

Browse files
Collect each test's screen reference cycle in TestCurses
Each test's newterm() screen forms a window<->screen reference cycle, reclaimed only by the cyclic GC. Collect it while the screen is still current, so the windows' delwin() succeeds; collected later, on a non-current screen, it fails (an unraisable error that trips --fail-env-changed on macOS). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2165c49 commit 03f0d8c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/test/test_curses.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ def setUp(self):
124124
infd = stdout_fd
125125
self.screen = curses.newterm(term, stdout_fd, infd)
126126
self.stdscr = self.screen.stdscr
127-
# Drop the screen after the test so the screens do not pile up: a
128-
# window keeps its screen alive through a reference cycle, and
129-
# unittest keeps every test instance for the whole run.
127+
# Drop the screen after the test, and collect the window<->screen
128+
# reference cycle while the screen is still current, so delwin()
129+
# succeeds; collected later, on a non-current screen, it fails
130+
# (unraisable on macOS).
131+
self.addCleanup(gc_collect)
130132
self.addCleanup(setattr, self, 'screen', None)
131133
self.addCleanup(setattr, self, 'stdscr', None)
132134
else:

0 commit comments

Comments
 (0)