Skip to content

click.testing.CliRunner.invoke swallows programming errors #136

@wallrj

Description

@wallrj

CliRunner.invoke captures all exceptions:

...which makes it difficult to see programming errors.

Perhaps it should only catch click specific exceptions.

Here's an example.

import unittest

import click
from click.testing import CliRunner

@click.command()
@click.argument('bar')
def foo():
    """
    This command will raise a TypeError('foo() takes no arguments (1 given)',)
    when called via runner.invoke, but you won't see that when testing with
    CliRunner.invoke.
    """
    click.echo('hello world\n')



class VolumeTests(unittest.TestCase):
    def test_noarguments(self):
        runner = CliRunner()
        result = runner.invoke(foo, ['baz'])
        self.assertEqual(b'hello world\n', result.output)
        # Only way to see the error is by examining the exception attribute.
        # self.assertEqual(b'', result.exception)



if __name__ == '__main__':
    unittest.main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions