Title: test_curses fails in every Ubuntu CI run's parallel phase: test_use_prescr_screen leaves use_env(False) set, so newterm() fails with TERM=linux · Issue #157170 · python/cpython · GitHub
Open Graph Title: test_curses fails in every Ubuntu CI run's parallel phase: test_use_prescr_screen leaves use_env(False) set, so newterm() fails with TERM=linux · Issue #157170 · python/cpython
X Title: test_curses fails in every Ubuntu CI run's parallel phase: test_use_prescr_screen leaves use_env(False) set, so newterm() fails with TERM=linux · Issue #157170 · python/cpython
Description: Bug report Bug description: On every recent Ubuntu CI job on main, test_curses fails in the parallel phase with 138 errors and only passes on the automatic sequential rerun, so the failure never shows up as a red check. I sampled the las...
Open Graph Description: Bug report Bug description: On every recent Ubuntu CI job on main, test_curses fails in the parallel phase with 138 errors and only passes on the automatic sequential rerun, so the failure never sh...
X Description: Bug report Bug description: On every recent Ubuntu CI job on main, test_curses fails in the parallel phase with 138 errors and only passes on the automatic sequential rerun, so the failure never sh...
Opengraph URL: https://github.com/python/cpython/issues/157170
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_curses fails in every Ubuntu CI run's parallel phase: test_use_prescr_screen leaves use_env(False) set, so newterm() fails with TERM=linux","articleBody":"# Bug report\n\n### Bug description:\n\nOn every recent Ubuntu CI job on main, `test_curses` fails in the parallel phase with 138 errors and only passes on the automatic sequential rerun, so the failure never shows up as a red check. I sampled the last 8 successful Tests runs: all 31 Ubuntu job runs (x86-64 and arm64, default and free-threading builds) show `test_curses failed (138 errors)` followed by `test_curses passed` on the rerun. Example, the free-threading job of https://github.com/python/cpython/actions/runs/34185684639: `test_curses failed (138 errors)` at 0:11:27 and `[1/1] test_curses passed` at 0:13:58. Every error is the same:\n\n```\nERROR: test_add_string_behavior (test.test_curses.TestCurses.test_add_string_behavior)\n File \".../Lib/test/test_curses.py\", line 183, in setUp\n self.screen = curses.newterm(term, stdout_fd, infd)\ncurses.error: newterm() returned NULL\n```\n\nThe 138 errors are every test of `TestCurses` (and the textbox/panel tests that share its `setUp()`), so in effect those tests only run in the rerun, and only there because the rerun re-runs the failed tests by name and therefore skips `ScreenTests`.\n\n### Cause\n\n`ScreenTests.test_use_prescr_screen` ends with\n\n```python\n # Affecting the state before initscr() is what such a screen is for.\n prescr.use(lambda scr: curses.use_env(False))\n```\n\nand never turns `use_env` back on. `curses.use_env()` calls ncurses' `use_env()`, which sets the process-wide default `_nc_prescreen.use_env`, not a property of the screen that is current when it is called, and every screen created afterwards copies that default. With `use_env(False)`, ncurses takes the screen size from the terminfo `lines` and `cols` capabilities alone, without the `LINES`/`COLUMNS` environment or the 24x80 fallback. The CI runners have `TERM=linux`, and the `linux` terminfo entry has no `lines` or `cols`:\n\n```\n$ infocmp -1 linux | grep -E 'lines#|cols#' # nothing\n$ infocmp -1 xterm | grep -E 'lines#|cols#' # cols#80 lines#24\n```\n\nso every `newterm()` after that test computes a -1x-1 screen and returns NULL. With `TERM=xterm` or `vt100` the size comes from terminfo and the module passes, which is why this does not show up on developer machines.\n\nI confirmed this with an ncurses 6.5 built with `--with-trace`. For a `newterm(\"linux\", ...)` after `test_use_prescr_screen`:\n\n```\ncalled {newterm(0xba7a54022bc0, \"linux\", 0xba7a53dd7120,0xba7a53d4a6c0)\nscreen size: terminfo lines = -1 columns = -1\nuseEnv:0 useTioctl:0\nscreen size is -1x-1\n```\n\nwhereas before that test, or after restoring `use_env(True)`, it reads `useEnv:1` and `screen size is 24x80`.\n\n### Reproducer\n\nOn Ubuntu 25.10 (ncurses 6.5, so the `newterm()`-based `setUp()` is used) with a debug build of main:\n\n```\n$ TERM=linux ./python -m test test_curses -u curses # test_curses failed (138 errors)\n$ TERM=xterm ./python -m test test_curses -u curses # test_curses passed\n```\n\nRestoring the setting in the test (`self.addCleanup(curses.use_env, True)` before the `prescr.use(...)` line) makes the module pass with `TERM=linux`, and a `--fast-ci` run then needs no rerun. I will open a PR.\n\nThe docs for `curses.use_env()` could also say that the setting is process-wide and not tied to a screen, since the comment in the test shows the opposite was assumed.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157171\n* gh-157207\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/iamsharduld","@type":"Person","name":"iamsharduld"},"datePublished":"2026-09-08T06:21:36Z","url":"https://github.com/python/cpython/issues/157170"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:93415f82-f2b4-c683-2cef-839c823c30b4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DDD0:2454CC:37DD7B6:46E37A8:6B01F24A |
| html-safe-nonce | 99b6930ab8250d534d09f748ed7716188db63bac5fd10c6526c3205dd01a2841 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREQwOjI0NTRDQzozN0REN0I2OjQ2RTM3QTg6NkIwMUYyNEEiLCJ2aXNpdG9yX2lkIjoiNTMxOTAyMDQ1MTg3NDMzNzM1NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 665d4f63bb54bccadd8f458ca6cdc52a5dd2bc7b01d168c75838b5f0fe051b12 |
| hovercard-subject-tag | issue:5382974104 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/157170/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cc64d9768ec628467e616b8c67ce29cde629c55ffbb1ab450ca37d6c8f99a2c3/python/cpython/issues/157170 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cc64d9768ec628467e616b8c67ce29cde629c55ffbb1ab450ca37d6c8f99a2c3/python/cpython/issues/157170 |
| og:image:alt | Bug report Bug description: On every recent Ubuntu CI job on main, test_curses fails in the parallel phase with 138 errors and only passes on the automatic sequential rerun, so the failure never sh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iamsharduld |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width