GeezerVison is showing github.com — gh-131178: Add tests for `ftplib` command-line interface by rudy-07 · Pull Request #161080 · python/cpython
Conversation
Add unit tests in Lib/test/test_ftplib.py covering the ftplib command-line interface (python -m ftplib):
- Empty invocation prints usage docstring and exits with code 0.
- Subprocess execution with
test.support.script_helper.assert_python_ok.
- Host connection and
-d debugging level adjustments.
-l (directory listing), -d (CWD), and -p (passive mode) command parsing.
- File retrieval (
RETR).
-r custom netrc file error handling.
Part of gh-131178.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add unit tests in Lib/test/test_ftplib.py covering the ftplib command-line interface: verifying usage message on empty invocation, subprocess invocation, host connection with debuglevel, directory and passive mode commands, file retrieval, and custom netrc file error handling.
|
All commit authors signed the Contributor License Agreement.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Could you check the failures in the CI?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Hi @orsenthil,
The initial failure was caused by missing parentheses on @requires_subprocess in Lib/test/test_ftplib.py, which caused a TypeError at import time when the test runner loaded the module.
I pushed commit 2f1b646 to fix the decorator invocation to @requires_subprocess(), and also mocked netrc.netrc in the command tests to ensure hermetic execution regardless of the runner environment.
All test jobs across all platforms have now passed. Please let me know if any further changes are needed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…lib.rst
Don't need this for the test only enhancement.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.
If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @rudy-07 for the PR, and @orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot AMD64 CentOS9 NoGIL 3.x (tier-1) has failed when building commit c29f95a.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1609/builds/7679) and take a look at the build logs.
- Check if the failure is related to this commit (c29f95a) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/1609/builds/7679
Failed tests:
Failed subtests:
- test_cli_retrieve_file - test.test_ftplib.CommandLineTest.test_cli_retrieve_file
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.itamaro-centos-aws.nogil/build/Lib/unittest/mock.py", line 1437, in patched
return func(*newargs, **newkeywargs)
File "/home/buildbot/buildarea/3.x.itamaro-centos-aws.nogil/build/Lib/test/test_ftplib.py", line 1246, in test_cli_retrieve_file
ftplib.test()
~~~~~~~~~~~^^
File "/home/buildbot/buildarea/3.x.itamaro-centos-aws.nogil/build/Lib/ftplib.py", line 968, in test
sys.stdout.buffer.write, 1024)
^^^^^^^^^^^^^^^^^
AttributeError: '_io.StringIO' object has no attribute 'buffer'
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot ARM64 macOS 3.x (tier-1) has failed when building commit c29f95a.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/725/builds/15020) and take a look at the build logs.
- Check if the failure is related to this commit (c29f95a) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/725/builds/15020
Failed tests:
Failed subtests:
- test_cli_retrieve_file - test.test_ftplib.CommandLineTest.test_cli_retrieve_file
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/unittest/mock.py", line 1437, in patched
return func(*newargs, **newkeywargs)
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_ftplib.py", line 1246, in test_cli_retrieve_file
ftplib.test()
~~~~~~~~~~~^^
File "/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/ftplib.py", line 968, in test
sys.stdout.buffer.write, 1024)
^^^^^^^^^^^^^^^^^
AttributeError: '_io.StringIO' object has no attribute 'buffer'
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot ARM Raspbian 3.x (tier-3) has failed when building commit c29f95a.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/424/builds/15603) and take a look at the build logs.
- Check if the failure is related to this commit (c29f95a) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/424/builds/15603
Failed tests:
Failed subtests:
- test_cli_retrieve_file - test.test_ftplib.CommandLineTest.test_cli_retrieve_file
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/var/lib/buildbot/workers/3.x.gps-raspbian.nondebug/build/Lib/unittest/mock.py", line 1437, in patched
return func(*newargs, **newkeywargs)
File "/var/lib/buildbot/workers/3.x.gps-raspbian.nondebug/build/Lib/test/test_ftplib.py", line 1246, in test_cli_retrieve_file
ftplib.test()
~~~~~~~~~~~^^
File "/var/lib/buildbot/workers/3.x.gps-raspbian.nondebug/build/Lib/ftplib.py", line 968, in test
sys.stdout.buffer.write, 1024)
^^^^^^^^^^^^^^^^^
AttributeError: '_io.StringIO' object has no attribute 'buffer'
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for merging! I noticed the buildbot failure in test_cli_retrieve_file caused by sys.stdout lacking a .buffer attribute under regrtest. I will open a follow-up PR shortly to mock sys.stdout properly.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot ARM64 Raspbian Debug 3.x (tier-3) has failed when building commit c29f95a.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1829/builds/3671) and take a look at the build logs.
- Check if the failure is related to this commit (c29f95a) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/1829/builds/3671
Failed tests:
Failed subtests:
- test_cli_retrieve_file - test.test_ftplib.CommandLineTest.test_cli_retrieve_file
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/mnt/ssd/buildbot/buildarea/3.x.savannah-raspbian/build/Lib/unittest/mock.py", line 1437, in patched
return func(*newargs, **newkeywargs)
File "/mnt/ssd/buildbot/buildarea/3.x.savannah-raspbian/build/Lib/test/test_ftplib.py", line 1246, in test_cli_retrieve_file
ftplib.test()
~~~~~~~~~~~^^
File "/mnt/ssd/buildbot/buildarea/3.x.savannah-raspbian/build/Lib/ftplib.py", line 968, in test
sys.stdout.buffer.write, 1024)
^^^^^^^^^^^^^^^^^
AttributeError: '_io.StringIO' object has no attribute 'buffer'
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I opened a follow-up PR to fix the sys.stdout.buffer AttributeError in est_cli_retrieve_file: #161135.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @rudy-07 for the PR, and @orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @rudy-07 for the PR, and @orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
orsenthil
added a commit
that referenced
this pull request
Nov 2, 2026
…61080) (#161153)
* gh-131178: Add tests for ftplib command-line interface
Add unit tests in Lib/test/test_ftplib.py covering the ftplib command-line interface: verifying usage message on empty invocation, subprocess invocation, host connection with debuglevel, directory and passive mode commands, file retrieval, and custom netrc file error handling.
(cherry picked from commit c29f95a)
Co-authored-by: Rudransh Shekhar <[email protected]>
Co-authored-by: Senthil Kumaran <[email protected]>
orsenthil
added a commit
that referenced
this pull request
Nov 2, 2026
…61080) (#161154)
* gh-131178: Add tests for ftplib command-line interface
Add unit tests in Lib/test/test_ftplib.py covering the ftplib command-line interface: verifying usage message on empty invocation, subprocess invocation, host connection with debuglevel, directory and passive mode commands, file retrieval, and custom netrc file error handling.
(cherry picked from commit c29f95a)
Co-authored-by: Rudransh Shekhar <[email protected]>
Co-authored-by: Senthil Kumaran <[email protected]>
Reviewers
giampaolo
Awaiting requested review from giampaolo
giampaolo is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|