Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when calling CLI command with an argument with run from Pytest #14

Open
bolinocroustibat opened this issue Aug 22, 2024 · 0 comments

Comments

@bolinocroustibat
Copy link

bolinocroustibat commented Aug 22, 2024

Minicli version : 0.5.3
Pytest version : 8.3.0

When calling a minicli command with run with an argument (e.g. run("test_method", test_arg="test")) in a Pytest test, we get the following error:
argparse.ArgumentError: the following arguments are required: test_arg

Detailed example:

In the CLI commands definition file:

from minicli import cli

@cli
async def test_method(test_arg: str):
    print(test_arg)

In a Pytest test.py file:

from minicli import run

def test_call():
    run("test_method", test_arg="test")

This is run with pytest test.py.

Note: this does not happen when the CLI command has a default argument. In that case, the argument os properly passed and properly overrides the default argument, for example when the CLI is defined this way:

from minicli import cli

@cli
async def test_method(test_arg: str = "default"):
    print(test_arg)

...then pytest test.py will not fail and will properly output "test".

@bolinocroustibat bolinocroustibat changed the title Error when calling CLI method with an argument with run from Pytest Error when calling CLI command with an argument with run from Pytest Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant