gh-157170: Restore use_env() after test_use_prescr_screen in test_curses by iamsharduld · Pull Request #157171 · python/cpython · GitHub
Skip to content

gh-157170: Restore use_env() after test_use_prescr_screen in test_curses - #157171

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
iamsharduld:fix-curses-use-env-cleanup
Sep 9, 2026
Merged

gh-157170: Restore use_env() after test_use_prescr_screen in test_curses#157171
serhiy-storchaka merged 2 commits into
python:mainfrom
iamsharduld:fix-curses-use-env-cleanup

Conversation

@iamsharduld

@iamsharduld iamsharduld commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

test_use_prescr_screen turns use_env off to show that a new_prescr() screen can be used to affect state before initscr(), and never turns it back on. curses.use_env() calls ncurses' use_env(), which sets the process-wide default (_nc_prescreen.use_env) that every later screen copies, not a property of the screen that is current at the time. With it off, ncurses sizes a screen from the terminfo lines/cols capabilities alone, and the linux entry used by the CI runners has none, so every newterm() for the rest of the process returns NULL. That is the 138 errors test_curses reports in the parallel phase of every Ubuntu CI run (all 31 Ubuntu job runs in the last 8 successful runs on main); the sequential rerun passes only because it re-runs the failed tests by name and so never runs ScreenTests first. Details, including an ncurses trace of the failing newterm(), are in the issue.

This restores the setting with addCleanup(). Verified on Ubuntu 25.10 with ncurses 6.5 (the newterm-based setUp() needs ncurses 6.5 or newer):

  • TERM=linux ./python -m test test_curses -u curses: 138 errors before, passes after (three consecutive runs).
  • TERM=linux ./python -m test --fast-ci test_curses: no rerun needed after.
  • TERM=xterm still passes.

On macOS the ScreenTests are skipped (ncurses 6.0), which is why this was invisible on developer machines.

…st_curses

curses.use_env() sets a process-wide ncurses default, not a property of
the screen it is called on. test_use_prescr_screen turned it off and
never turned it back on, so every newterm() in the rest of the process
took the screen size from terminfo alone. For a terminfo entry with no
size, such as "linux" on the CI runners, that makes newterm() return
NULL: test_curses failed with 138 errors in the parallel phase of every
Ubuntu CI run and only passed on the rerun, which skips ScreenTests.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, and thank you for the trace.

Please drop the NEWS entry. This is a fix to unreleased test. It does not need a NEWS entry.

Please simplify the comment, it is too verbose. One addition line would be enough.

@iamsharduld

Copy link
Copy Markdown
Contributor Author

@bedevere-app

bedevere-app Bot commented Sep 9, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

: please review the changes made to this pull request.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka
serhiy-storchaka merged commit 5f14441 into python:main Sep 9, 2026
53 of 56 checks passed
@bedevere-bot

Copy link
Copy Markdown

maurycy added a commit to maurycy/cpython that referenced this pull request Sep 10, 2026
* main: (158 commits)
  pythongh-156924: Try reifying lazy imports in `ForwarRef.evaluate()` (python#156940)
  pythongh-156233: Fix typos and code snippet errors in the docs (python#156475)
  pythongh-156837: Refer to yield expressions in generator function definitions (pythonGH-156863)
  pythongh-155292: Skip updating unicodedata with mismatched interpreter (pythonGH-157066)
  pythongh-157170: Document the scope of global curses settings (pythonGH-157207)
  pythongh-155966: Correct handling of `math.tanpi` poles (python#155980)
  pythongh-157170: Restore use_env() after test_use_prescr_screen in test_curses (pythonGH-157171)
  pythongh-156910: fix deadlock in type_set_abstractmethods under free-threading (python#156948)
  pythongh-155648: Write the empty and placeholder IDLE tests (python#156260)
  pythongh-153569: centralize formatted-string state and source spans (python#156484)
  pythongh-157137: Mark the PEP 820 soft deprecations as 3.15, not `next` (python#157138)
  pythongh-152433: Use regular LoadLibrary in UWP for Windows system libs (pythonGH-156972)
  pythongh-121617: Fix Py_CLEAR() memcpy in C++: replace NULL with _Py_NULL (python#157188)
  pythongh-157135: Fix documentation errors in the `math.atan{2}pi` functions (python#157136)
  pythongh-121617: Fix Py_CLEAR() in C++: replace NULL with _Py_NULL (python#157067)
  pythongh-156774: Speed up pdb startup with asyncio guard (python#156775)
  pythongh-156109: Allow static, non-framework iOS builds (python#156110)
  pythongh-156780: Emscripten: add missing EM_JS_DEPS (python#156798)
  pythongh-152936: Make privileged functions available on Android (python#152977)
  pythongh-123018: Keep the libedit history file header when truncating (pythonGH-157165)
  ...
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
…st_curses (pythonGH-157171)

curses.use_env() sets a process-wide ncurses setting, not a property of
the screen it is called on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants