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
Provenance
- Commit
f1a8460- Tree
acd829a- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
52f9d9b
3 files changed+17 added−3 removed
modified:click/testing.py+14 added-3 removed
64 unmodified lines65 66 class Result(object):67 """Holds the captured result of an invoked CLI script."""68 69- 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_info81 82 @property83 def output(self):84 """The output as unicode string."""141 unmodified lines226 227 This returns a :class:`Result` object.228 229 .. versionadded:: 3.0227- The ``catch_exceptions`` parameter was added.230+ The ``catch_exceptions`` parameter was added.231 232+ .. versionchanged:: 3.0233+ The result object now has an `exc_info` attribute with the234+ traceback if available.235+236 :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 lines252 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()266 267 return Result(runner=self,268 output_bytes=output,269 exit_code=exit_code,260- exception=exception)270+ exception=exception,271+ exc_info=exc_info)272 273 @contextlib.contextmanager274 def isolated_filesystem(self):275 """A context manager that creates a temporary folder and changes13 unmodified linesmodified:tests/test_testing.py+2 added
101 unmodified lines102 runner = CliRunner()103 104 result = runner.invoke(cli)105 assert isinstance(result.exception, CustomError)106+ assert type(result.exc_info) is tuple107+ assert len(result.exc_info) == 3108 109 with pytest.raises(CustomError):110 runner.invoke(cli, catch_exceptions=False)111 4 unmodified linesmodified:CHANGES+1 added
12 unmodified lines13 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.18 19 Version 2.120 -----------21 69 unmodified lines