Skip to content
Myr

Added exc_info to result.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 52f9d9b · Browse files · 3 files+17 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+17 added−3 removed

  • tests:+2 added−0 removed
  • other:+15 added−3 removed

3 files+17 added−3 removed

modified:click/testing.py+14 added-3 removed
64 unmodified lines
6566class Result(object):67 """Holds the captured result of an invoked CLI script."""6869 def __init__(self, runner, output_bytes, exit_code, exception):69 def __init__(self, runner, output_bytes, exit_code, exception,70 exc_info=None):71 #: The runner that created the result72 self.runner = runner73 #: The output as bytes.74 self.output_bytes = output_bytes75 #: The exit code as integer.76 self.exit_code = exit_code77 #: The exception that happend if one did.78 self.exception = exception79 #: The traceback80 self.exc_info = exc_info8182 @property83 def output(self):84 """The output as unicode string."""
141 unmodified lines
226227 This returns a :class:`Result` object.228229 .. versionadded:: 3.0227 The ``catch_exceptions`` parameter was added.230 The ``catch_exceptions`` parameter was added.231232 .. versionchanged:: 3.0233 The result object now has an `exc_info` attribute with the234 traceback if available.235236 :param cli: the command to invoke237 :param args: the arguments to invoke238 :param input: the input data for `sys.stdin`.239 :param env: the environment overrides.240 :param catch_exceptions: Whether to catch any other exceptions than241 ``SystemExit``.242 :param extra: the keyword arguments to pass to :meth:`main`.243 """244 exc_info = None245 with self.isolation(input=input, env=env) as out:246 exception = None247 exit_code = 0248
3 unmodified lines
252 except SystemExit as e:253 if e.code != 0:254 exception = e255 exit_code = e.code256 exc_info = sys.exc_info()257 except Exception as e:258 if not catch_exceptions:259 raise260 exception = e261 exit_code = -1262 exc_info = sys.exc_info()263 finally:264 sys.stdout.flush()265 output = out.getvalue()266267 return Result(runner=self,268 output_bytes=output,269 exit_code=exit_code,260 exception=exception)270 exception=exception,271 exc_info=exc_info)272273 @contextlib.contextmanager274 def isolated_filesystem(self):275 """A context manager that creates a temporary folder and changes
13 unmodified lines
modified:tests/test_testing.py+2 added
101 unmodified lines
102 runner = CliRunner()103104 result = runner.invoke(cli)105 assert isinstance(result.exception, CustomError)106 assert type(result.exc_info) is tuple107 assert len(result.exc_info) == 3108109 with pytest.raises(CustomError):110 runner.invoke(cli, catch_exceptions=False)111
4 unmodified lines
modified:CHANGES+1 added
12 unmodified lines
13 a minimal width.14- added a way to not swallow exceptions in the test system.15- added better support for colors with pagers and ways to16 override the autodetection.17- the CLI runner's result object now has a traceback attached.1819Version 2.120-----------21
69 unmodified lines