Skip to content

gh-131178: Add tests for ftplib command-line interface - #161080

Merged
orsenthil merged 3 commits into
python:mainfrom
rudy-07:test-ftplib-cli
Nov 1, 2026
Merged

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

Conversation

@rudy-07

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

Copy link
Copy Markdown
Contributor

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.

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.
Copilot AI balanced review requested due to automatic review settings November 1, 2026 14:23
@rudy-07
rudy-07 requested a review from giampaolo as a code owner November 1, 2026 14:23
@python-cla-bot

python-cla-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@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

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.

@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Nov 1, 2026
@orsenthil

Copy link
Copy Markdown
Member

Could you check the failures in the CI?

@rudy-07

rudy-07 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

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.

@orsenthil orsenthil removed the type-feature A feature request or enhancement label Nov 1, 2026
…lib.rst

Don't need this for the test only enhancement.
@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

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.

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 1, 2026
@orsenthil orsenthil added skip news and removed type-feature A feature request or enhancement labels Nov 1, 2026
@orsenthil orsenthil added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 1, 2026
@orsenthil
orsenthil enabled auto-merge (squash) November 1, 2026 19:56
@orsenthil
orsenthil merged commit c29f95a into python:main Nov 1, 2026
63 of 64 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @rudy-07 for the PR, and @orsenthil for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 CentOS9 NoGIL 3.x (tier-1) has failed when building commit c29f95a.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. 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.
  4. Check if the failure is related to this commit (c29f95a) or if it is a false positive.
  5. 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:

  • test_ftplib

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'

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 macOS 3.x (tier-1) has failed when building commit c29f95a.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. 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.
  4. Check if the failure is related to this commit (c29f95a) or if it is a false positive.
  5. 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:

  • test_ftplib

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'

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM Raspbian 3.x (tier-3) has failed when building commit c29f95a.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. 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.
  4. Check if the failure is related to this commit (c29f95a) or if it is a false positive.
  5. 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:

  • test_ftplib

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'

@rudy-07

rudy-07 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

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.

@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 Raspbian Debug 3.x (tier-3) has failed when building commit c29f95a.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. 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.
  4. Check if the failure is related to this commit (c29f95a) or if it is a false positive.
  5. 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:

  • test_ftplib

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'

@rudy-07

rudy-07 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

I opened a follow-up PR to fix the sys.stdout.buffer AttributeError in est_cli_retrieve_file: #161135.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants