Skip to content

Conversation

@FazeelUsmani
Copy link

@FazeelUsmani FazeelUsmani commented Nov 11, 2025

Addresses #13973

Summary

Previously, pytest command-line options were only visible via pytest --help, making them difficult to discover and browse online. This PR adds a dedicated CLI options reference page to improve discoverability and provide a better documentation experience.

Changes

Added a new documentation page (doc/en/how-to/cli-options.rst) that organizes commonly used pytest CLI options into logical categories:

  • Running and Selecting Tests (-k, -m, -x, --maxfail, --lf, --ff, --sw)
  • Output and Verbosity (-v, -q, --tb, -l, -r)
  • Reporting and Output Files (--junit-xml, --durations, -s)
  • Collection and Test Discovery (--collect-only, --pyargs, --ignore)
  • Debugging (--pdb, --trace, --fixtures, --setup-show)
  • Configuration (-c, --basetemp, -o)
  • Logging (--log-cli-level, --log-level, --log-file)
  • Warnings (--disable-warnings, -W)
  • Common Option Combinations for typical workflows

Each section includes clear examples, brief explanations, and cross-references to related documentation. The page also links to the complete command-line flag reference for users who need the exhaustive list.

Files Changed

  • Added doc/en/how-to/cli-options.rst - new CLI options reference page (307 lines)
  • Updated doc/en/how-to/index.rst - added the new page to the table of contents
  • Added changelog/4492.doc.rst - changelog entry

Testing

The documentation was successfully built using Sphinx with no errors. All cross-references are valid and the generated HTML renders correctly.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 11, 2025
@FazeelUsmani FazeelUsmani marked this pull request as draft November 11, 2025 14:34
@FazeelUsmani FazeelUsmani marked this pull request as ready for review November 11, 2025 14:59
@bluetech
Copy link
Member

Hi @FazeelUsmani, can you open an issue with your proposal? It will allow us to have a place to discuss the idea not in the context of a specific PR.

@FazeelUsmani
Copy link
Author

Sure, let me open

@bluetech
Copy link
Member

Thanks for the update!

Quick preview link: https://pytest--13930.org.readthedocs.build/en/13930/reference/reference.html#command-line-flags

Please see my comment below.


When a flag has short and long (or alternatives) it is rendered as:

image

First, I think it would be nicer to render the alternatives in a single line, separated by commas. It makes it clearer they are alternatives, and not just something that we forgot to document.

Second, I think we should only have one canonical optionval per set of alternatives, probably the long spelling. I don't think we should have multiple ways to reference an option.


I think some of the options can have better links to places in the docs which discuss them, but I realize this is hard work, so not a blocker, maybe can be improved in the future.


Another thing we can improve in the future is to go over the docs and when a flag is mentioned make it a hyperlink using optionval. Also hard work, not a blocker for this PR.


The optionval reference should only include the flag name, not the value, e.g. in .. optionval:: --ignore-glob=path the path should not be included, otherwise it's unnatural to reference it.

Also, I think it would be better if the optionval also didn't include the --. If we standardize on only using the long spelling (when available) as the canonical then it should not be ambiguous. So in the example above, would reference using :optionval:`ignore-glob` and render as --ignore-blob. Well actually maybe it's better to keep the --. Happy to hear opinions...

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

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants