pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Add shell completions by shtab

Open Freed-Wu opened this issue 3 years ago • 6 comments

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.
  • [X] 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:

  • [x] 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 ..

  • [x] Add yourself to AUTHORS in alphabetical order.

Freed-Wu avatar Sep 17 '22 17:09 Freed-Wu

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

RonnyPfannschmidt avatar Sep 17 '22 19:09 RonnyPfannschmidt

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 avatar Sep 18 '22 06:09 Freed-Wu

How to fix coverage check failure?

Freed-Wu avatar Sep 18 '22 17:09 Freed-Wu

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

RonnyPfannschmidt avatar Sep 18 '22 19:09 RonnyPfannschmidt

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.

Freed-Wu avatar Sep 18 '22 19:09 Freed-Wu

This had been approved, but sadly went stale in the meantime. @Freed-Wu do you want to rebase and see, if we can merge it then?

obestwalter avatar Jun 20 '24 11:06 obestwalter