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()
Click 3.0 has a flag to control this.
runner.invoke(loader.loader, ["-t", "rdr", fname], catch_exceptions=False)
A note about this in the testing docs would be great
Looks like this is covered by the documentation here: https://click.palletsprojects.com/en/7.x/api/#testing
Most helpful comment
runner.invoke(loader.loader, ["-t", "rdr", fname], catch_exceptions=False)