Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shell completions by shtab #10304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Freed-Wu
Copy link

See #1992

pytest --print-completion bash | sudo tee /usr/share/bash-completion/completions/pytest
pytest --print-completion tcsh | sudo tee /etc/profile.d/pytest.completion.csh
pytest --print-completion zsh | sudo tee /usr/share/zsh/site-functions/_pytest
❯ pytest --<TAB>
option
--assert                          Control assertion debugging tools.
'plain' performs no assertion debugging.
'rewrite' (the default) rewrites assert statements in test modules on import to provide assert expression information.
--basetemp                        Base temporary directory for this test run. (Warning: this directory is removed if it exists.)
--cache-clear                     Remove all cache contents at start of test run
--cache-show                      Show cache contents, don't perform collection or tests. Optional argument: glob (default: '*').
--capture                         Per-test capturing method: one of fd|sys|no|tee-sys
...
❯ pytest --log-file <TAB>
log_file
AUTHORS             CHANGELOG.rst       CODE_OF_CONDUCT.md  extra/              pyproject.toml      scripts/            src/                tox.ini
bench/              CITATION            CONTRIBUTING.rst    LICENSE             README.rst          setup.cfg           testing/
changelog/          codecov.yml         doc/                OPENCOLLECTIVE.rst  RELEASING.rst       setup.py            TIDELIFT.rst
  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself.

If this change fixes an issue, please:

  • Add text like closes #XYZW to the PR description and/or commits (where XYZW is the issue number). See the github docs for more information.

Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:

  • Create a new changelog file in the changelog folder, with a name like <ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.

    Write sentences in the past or present tense, examples:

    • Improved verbose diff output with sequences.
    • Terminal summary statistics now use multiple colors.

    Also make sure to end the sentence with a ..

  • Add yourself to AUTHORS in alphabetical order.

@RonnyPfannschmidt
Copy link
Member

as far as i recall we use argcomplete to also handle options added by pytest plugins after the fact or locally
i wonder how to enable something similar for this as pytest completion is optionally tricky

@@ -12,6 +12,11 @@
from _pytest.config import PrintHelp
from _pytest.config.argparsing import Parser

try:
Copy link
Member

Choose a reason for hiding this comment

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

if we repeat that all over the place it might make sense to have a single module that exposes the api we need to have a optional dep

Copy link
Author

@Freed-Wu Freed-Wu Sep 18, 2022

Choose a reason for hiding this comment

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

Your meaning is wrapping the code to expose an API, right?

@Freed-Wu
Copy link
Author

handle options added by pytest plugins after the fact or locally

If any plugin add new option for pytest, I think regenerating the shell script can solve this problem.

@Freed-Wu
Copy link
Author

How to fix coverage check failure?

@RonnyPfannschmidt
Copy link
Member

i beleive the coverage diff issue can be ignored in this case

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

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

as far as i understand, this simply adds shtab generate support without touching the argcomplete dynamic support

i do wonder if we could add a better argparse wrapper to manage import costs there (but thats a followup)

it may be sensible/necessary to have better type values in the shims
but i would consider creating a better typesafe + shtab aware argpase wrapper a followup exercise)

thanks for getting this started ,i like the idea of a quick tab complete very much

src/_pytest/_shtab.py Show resolved Hide resolved
See pytest-dev#1992

pytest --print-completion bash | sudo tee /usr/share/bash-completion/completions/pytest
pytest --print-completion tcsh | sudo tee /etc/profile.d/pytest.completion.csh
pytest --print-completion zsh | sudo tee /usr/share/zsh/site-functions/_pytest
@Freed-Wu
Copy link
Author

i beleive the coverage diff issue can be ignored in this case

OK.

i like the idea of a quick tab complete very much

Me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants