You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the Typer documentation, with the integrated search.
I already searched in Google "How to X in Typer" and didn't find any information.
I already read and followed all the tutorials in the docs and didn't find an answer.
I already checked if it is not related to Typer but to Click.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromtyperimportTyper, Argumentfromtyper.testingimportCliRunnerfromtypingimportAnnotatedapp=Typer()
defautocomplete():
"""A function fetching autocomplete options from an API"""return ["Alpha", "Bravo", "Charlie"]
@app.command()defcmd(name: Annotated[str, Argument(autocompletion=autocomplete)]):
print(name)
result=CliRunner().invoke(app, "cmd", input="\t\t")
Description
Given a command with an argument with custom autocomplete logic, is there a way to test the autocomplete functionality in pytest?
While it would be possible to test just the autocomplete functionality in a unittest on its own, this is not really suitable in cases where the autocomplete for one argument depends on one of the other arguments/options.
For such cases, it would make sense if there is a way to test the autocompletion using the CliRunner somehow.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Given a command with an argument with custom autocomplete logic, is there a way to test the autocomplete functionality in pytest?
While it would be possible to test just the autocomplete functionality in a unittest on its own, this is not really suitable in cases where the autocomplete for one argument depends on one of the other arguments/options.
For such cases, it would make sense if there is a way to test the autocompletion using the CliRunner somehow.
Operating System
Linux
Operating System Details
Rocky Linux 8
Typer Version
0.21.1
Python Version
3.12
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions