CliRunner fails on app with added Click command #732
Answered
by
svlandeg
epogrebnyak
asked this question in
Questions
-
First Check
Commit to Help
Example Codeimport click
import typer
app = typer.Typer()
@app.command()
def top():
"""
Top level command, form Typer
"""
print("The Typer app is at the top level")
@app.callback()
def callback():
"""
Typer app, including Click subapp
"""
@click.command()
@click.option("--name", prompt="Your name", help="The person to greet.")
def hello(name):
"""Simple program that greets NAME for a total of COUNT times."""
click.echo("Hello %s!" % name)
typer_click_object = typer.main.get_command(app)
typer_click_object.add_command(hello, "hello")
from typer.testing import CliRunner
runner = CliRunner()
runner.invoke(typer_click_object, ["hello", "--name", "Camila"])
print(runner)
"""
/home/codespace/.python/current/bin/python3 /workspaces/abacus/abacus/typer_cli/sample.py
Traceback (most recent call last):
File "/workspaces/abacus/abacus/typer_cli/sample.py", line 36, in <module>
runner.invoke(typer_click_object, ["hello", "--name", "Camila"])
File "/home/codespace/.python/current/lib/python3.10/site-packages/typer/testing.py", line 20, in invoke
use_cli = _get_command(app)
File "/home/codespace/.python/current/lib/python3.10/site-packages/typer/main.py", line 341, in get_command
if typer_instance._add_completion:
AttributeError: 'TyperGroup' object has no attribute '_add_completion'
""" Description
Operating SystemWindows Operating System DetailsNo response Typer Version0.9.0 Python VersionPython 3.10.9 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
svlandeg
Mar 22, 2024
Replies: 1 comment
-
Hi! For this example code to work, you'll actually need to use
That will give you the required output:
You can see the implementation of this example here, and its unit tests checking this behaviour here - that might further clarify things! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
svlandeg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
For this example code to work, you'll actually need to use
That will give you the required output: