Skip to content

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

Closed

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()

Activity

  1. changed the title [-]click.testing.invoke swallows programming errors[/-] [+]click.testing.CliRunner.invoke swallows programming errors[/+] on Jun 9, 2014
  2. mitsuhiko commented on Jun 14, 2014

    @mitsuhiko
    Contributor

    Click 3.0 has a flag to control this.

  3. jongio commented on Jan 29, 2018

    @jongio

    runner.invoke(loader.loader, ["-t", "rdr", fname], catch_exceptions=False)

  4. jsmedmar commented on Jun 4, 2018

    @jsmedmar

    A note about this in the testing docs would be great

  5. deleted a comment from lucidsushi on Jan 16, 2020
  6. simonw commented on Jun 23, 2020

    @simonw
    Contributor
  7. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  8. added
    test runner
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    test runner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions