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()
CliRunner.invokecaptures all exceptions:...which makes it difficult to see programming errors.
Perhaps it should only catch
clickspecific exceptions.Here's an example.