Skip to content

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

Open
@j19sch

Description

@j19sch

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?

Activity

added
plugin: argcompleterelated to the argcomplete builtin plugin
type: enhancementnew feature or API change, should be merged into features branch
on Jul 2, 2019
nicoddemus

nicoddemus commented on Jul 2, 2019

@nicoddemus
Member

Hi @j19sch,

Thanks for writing.

I don't use argcomplete myself (I'm on Windows so I use other tag-completion mechanisms), so I can't really help how to approach this. I suspect you can learn a lot by reading src/_pytest/_argcomplete.py and playing around with it though. We definitely would love a patch with this feature. 👍

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: argcompleterelated to the argcomplete builtin plugintype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nicoddemus@j19sch

        Issue actions

          add completion of node ids (test classes/functions) for argcomplete · Issue #5514 · pytest-dev/pytest