Skip to content

Conversation

@tom-dalton-fanduel
Copy link
Contributor

I'm using click (with standalone_mode=False) as the command-parsing module for a chat bot. It's awesome! In the simplest case, I have commands structured like this:

@sammich.command()
@click.option("--filling", default="sad, empty")
def make(filling):
    """Demo for click options."""
    return f"Here you go, have a {filling} sammich"

For more complex stuff there's other ways to send messages back from the bot, but using the return value of the command to send simple messages has worked really well.

Testing commands like this is a bit of a pain. I can use the CliRunner and see that the "exit code" is 0, however, while the CliRunner (via the Result object) allows access to stdout, stderr, exit code etc, it doesn't capture the invocation result/return value. While it's a fairly unusual use case, it looked like it might be fairly straightforward to do and it turns out it is (at least... I think so!).

With this PR, I can more easily test my simple commands' return values (the new test in test_testing.py is exactly what I want to do for my own simple commands.)

@davidism
Copy link
Member

Changed to use return_value instead of the rv acronym. Added changelog.

@davidism davidism added this to the 8.0.0 milestone Aug 10, 2020
@davidism davidism merged commit 990ca8e into pallets:master Aug 10, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
@tom-dalton-fanduel tom-dalton-fanduel deleted the allow-testing-command-result-capture branch July 15, 2021 12:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants