pytest-dev / pytest-dev/pytest

add completion of node ids (test classes/functions) for argcomplete

Open
#5,514 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: argcomplete type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

Often enough I want to run a single test via the CLI. Tab completion (with or without argcomplete) works fine to get to the file, but completion for node ids (test classes/functions) is not supported.
As a workaround I either copy-paste the name of the test from my IDE, or do a --collect-only -q to copy-paste from there.

What I'd like to pytest to do, is that if I add a double colon :: after the file name, I get tab completion for the node ids (test classes/functions) in the file.

So if I have:

test_file.py
|- test_func_one
|- test_func_two
|- TestClass
    |- test_method
  • completion of pytest test_file.py:: would display test_func_one test_func_two TestClass
  • completion of pytest test_file.py::test_o would result in pytest test_file.py::test_one
  • completion of pytest test_file.py::TestClass:: would result in pytest test_file.py::TestClass::test_method

Open question: what to do with parameterized tests? --collect-only shows them as separate tests, but I'm not aware of a way to run them from the CLI as a separate test.

Depending on the complexity I might be interested in trying to implement this. (It would be my first contribution to the pytest codebase.) I assume implementing this completion would involve collecting all tests in src/_pytest/_argcomplete.py in FastFilesCompleter or in a new completer, if the path ends with a double colon?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/_pytest/_argcomplete.py, especially FastFilesCompleter, and inspect how pytest --collect-only -q represents node ids. Define completion after a file path and after a class node, including the parameterized-test question raised in the issue. Done means the shown file, function, and class-method completion examples work from the CLI.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.