Repository navigation
Add tests for command-line interface #131178
Description
While working on #130160 and #93096 it was decided that it would be worth paying attention to the problem of lack of tests for command line interface.
List of all cli modules is in the documentation: https://docs.python.org/dev/library/cmdline.html
Many modules are missing command line interface tests, so I suggest using this issue to submit PRs for now only for well-documented interfaces, for example:
-
tokenize(gh-131178: Add tests fortokenizecommand-line interface #131274) -
platform(gh-131524: Update platform CLI to use argparse #131542) -
pickle(gh-131178: Add tests forpicklecommand-line interface #131275) -
ast(gh-131178: Add tests forastcommand-line interface #133329) -
pickletools(gh-131178: Add tests forpickletoolscommand-line interface #131287) -
http.server(gh-131178: Add tests for http.server command-line interface #132540) -
profile(gh-131178: Add CLI tests for profile module #134103) -
cProfile(gh-131178: Add CLI tests for cProfile #134269) -
site( gh-131178: Add tests forsitecommand-line interface #133582)
TODO: Make sure all documented have tests for CLI (others are not so important as it has not been decided what to do with them yet)
You can use PR #127759 for dis module or #118132 for random module as a reference.
And I also suggest using subprocess.Popen to allocate a separate resource since some modules can block a lot of time.
Important
For those who want to work on the issue, please:
- Select one module for which tests will be improved. It's easier to review and backport.
- Open a pull request with the following title:
gh-131178: Add tests for `MODULE_NAME` command-line interface
Linked PRs
- gh-131178: Add tests for
tokenizecommand-line interface #131274 - gh-131178: Add tests for
picklecommand-line interface #131275 - gh-131178: Add tests for
pickletoolscommand-line interface #131287 - gh-131178: Update help message for
timeitCLI #131326 - gh-131178: Add tests for http.server command-line interface #132540
- gh-131178: Add tests for
astcommand-line interface #133329 - gh-131178: Add tests for
sitecommand-line interface #133582 - gh-131178: Add CLI tests for profile module #134103
- gh-131178: fix SSL tests for
http.servercommand-line interface #134224 - gh-131178: Add CLI tests for cProfile #134269
- gh-131178: add E2E mockless tests for
http.servercommand-line interface #134279 - gh-131178: remove runtime tests for
http.serverCLI #134287 - gh-131178: Use
support.captured_stdoutandsupport.captured_stderr#137748 - gh-131178: Add tests for site command-line interface #137807
- gh-131178: Fix
test_unknown_flagfor platform CLI #137816 - [3.14] gh-131178: Add tests for
sitecommand-line interface (GH-133582) #137832 - [3.13] gh-131178: Add tests for
sitecommand-line interface (GH-133582) #137833 - gh-131178: Add tests for
sysconfigcommand-line interface #139934 - gh-131178: add tests for
filecmpcommand-line interface #139947 - gh-131178: add unittest for turtledemo #139983
- gh-131178: add tests for filecmp command-line interface #140199
- gh-131178: add tests for filecmp command-line interface #140200
- gh-131178: Add CLI tests for the profile module #143835
- gh-131178: Add tests for cProfile command-line interface #144918
- gh-131178: Add tests for pyclbr command-line interface #147995
- gh-131178: Add tests for mimetypes command-line interface #149681
- gh-131178: Fix mimetypes CLI docs to mention that errors go to stdout #149683
- gh-131178: Add tests for
quopricommand-line interface #149825 - gh-131178: Add more tests for json command-line interface #149868
- gh-131178: Add tests for zipapp command-line interface #150203
- [3.15] gh-131178: Fix mimetypes CLI docs, mention that errors go to stdout (GH-149683) #150655
- [3.14] gh-131178: Fix mimetypes CLI docs, mention that errors go to stdout (GH-149683) #150656
- gh-131178: Add tests for
thiscommand-line interface #151855 - gh-131178: Add CLI tests for pydoc module #151971
- gh-131178: Add tests for
pstatscommand-line interface #157133 - gh-131178: Add tests for
ensurepipcommand-line interface #157154 - gh-131178: Add tests for
profilemodule command-line interface #158542 - gh-131178: Add tests for
codecommand-line interface #158588 - gh-131178: Add tests for
calendarcommand-line interface #159045 - gh-131178: Add tests for \encodings.rot_13\ command-line interface #159299
Activity
hugovk commentedon Mar 13, 2025
See also the tests added in #118132, based on https://pythontest.com/testing-argparse-apps/
sobolevn commentedon Mar 13, 2025
@donbarbos I assigned this issue to you, since you mentioned that you are working on it :)
gh-131178: Add tests for `tokenize` command-line interface (#131274)
gh-131178: Update help message for `timeit` CLI (#131326)
pythongh-131178: Add tests for `tokenize` command-line interface (pyt…
gh-131178: Add tests for `pickle` command-line interface (#131275)
gh-131178: Add tests for `ast` command-line interface (#133329)
Merge remote-tracking branch 'origin/main' into call-len
pythongh-131178: Add tests for command-line interface
pythongh-131178: Add tests for command-line interface
pythongh-131178: Add tests for site command-line interface
65 remaining items
pythongh-131178: Add news entries for pydoc CLI tests
Merge branch 'python:main' into pythongh-131178-zipapp-cli-tests
pythongh-131178: Add tests for zipapp command-line interface
Start candidate database: axes 8, 5, 7 (Tools/JIT, stale PRs, tests)
Export wave-2 filecmp CLI tests patch (pythongh-131178 umbrella)
pythongh-131178: Add more tests for json command-line interface
pythongh-131178: Add tests for `quopri` command-line interface
Ghd-2077 commentedon Sep 4, 2026
I am interested in adding command-line interface tests for compileall.
Is this module still available to work on under gh-131178?
Ar-maan05 commentedon Sep 26, 2026
I have opened #149825 (quopri) and #149868 (json) for this issue. Both are ready for review and CI passes. If someone has time to take a look, I'd appreciate it.
cprentice9 commentedon Oct 2, 2026
I'd like to take
code. Its CLI is the__main__block inLib/code.pywith a single-qflag. There's nomain(), so I plan to run it as a subprocess withscript_helperand feed it stdin. The tests will cover:-qsuppressing the banner, andpython -q -m codedoing the same throughsys.flags.quiet-hand an unknown option-qisn't documented inDoc/library/code.rst. Should I add a short CLI section in the same PR, or keep this one to tests only?jikekei commentedon Oct 10, 2026
Hi, I'd like to contribute CLI subprocess tests for the symtable module under #131178.
I noticed that test_symtable.py already tests symtable.main() directly, but doesn't appear to test invocation through python -m symtable.
Would adding subprocess tests for successful execution and error handling be a useful contribution? Thank you!
pythongh-131178: Add NEWS entry for encodings.rot_13 CLI tests
pythongh-131178: Add tests for `encodings.rot_13` command-line interface
pythongh-131178: Add NEWS entry for encodings.rot_13 CLI tests
pythongh-131178: Fix NEWS entry to use inline code instead of mod role