Skip to content

gh-131178: Fix test_cli_retrieve_file when stdout is StringIO in test_ftplib - #161135

Merged
orsenthil merged 3 commits into
python:mainfrom
rudy-07:fix-ftplib-cli-stdout
Nov 2, 2026
Merged

orsenthil merged 3 commits into
python:mainfrom
rudy-07:fix-ftplib-cli-stdout

Conversation

@rudy-07

@rudy-07 rudy-07 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

In #161080, test_cli_retrieve_file was added to Lib/test/test_ftplib.py. In ftplib.test(), file retrieval calls ftp.retrbinary('RETR ' + file, sys.stdout.buffer.write, 1024) and sys.stdout.buffer.flush().

When tests run under regrtest on buildbots, sys.stdout is wrapped in an io.StringIO instance which lacks a .buffer attribute, causing AttributeError: '_io.StringIO' object has no attribute 'buffer'.

This patch mocks sys.stdout in CommandLineTest.test_cli_retrieve_file to prevent the error and assert the callback and flush calls.

Follow-up to #161080.

Mock sys.stdout in CommandLineTest.test_cli_retrieve_file so that
accessing sys.stdout.buffer does not fail when regrtest or other test
runners wrap sys.stdout in an io.StringIO object.
Copilot AI balanced review requested due to automatic review settings November 1, 2026 20:54
@rudy-07
rudy-07 requested a review from giampaolo as a code owner November 1, 2026 20:54
@bedevere-app bedevere-app Bot added awaiting review type-feature A feature request or enhancement labels Nov 1, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Nov 1, 2026
7 of 9 tasks
@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Nov 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@orsenthil orsenthil added skip news and removed type-feature A feature request or enhancement labels Nov 2, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 2, 2026
@orsenthil orsenthil removed the type-feature A feature request or enhancement label Nov 2, 2026
@orsenthil
orsenthil enabled auto-merge (squash) November 2, 2026 03:16
@orsenthil
orsenthil merged commit 3d81c05 into python:main Nov 2, 2026
55 of 56 checks passed
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