@@ -227,6 +227,11 @@ class CliRunner:
227
227
to `<stdout>`. This is useful for showing examples in
228
228
some circumstances. Note that regular prompts
229
229
will automatically echo the input.
230
+ :param catch_exceptions: Whether to catch any exceptions other than
231
+ ``SystemExit`` when running :meth:`~CliRunner.invoke`.
232
+
233
+ .. versionchanged:: 8.2
234
+ Added the ``catch_exceptions`` parameter.
230
235
231
236
.. versionchanged:: 8.2
232
237
``mix_stderr`` parameter has been removed.
@@ -237,10 +242,12 @@ def __init__(
237
242
charset : str = "utf-8" ,
238
243
env : cabc .Mapping [str , str | None ] | None = None ,
239
244
echo_stdin : bool = False ,
245
+ catch_exceptions : bool = True ,
240
246
) -> None :
241
247
self .charset = charset
242
248
self .env : cabc .Mapping [str , str | None ] = env or {}
243
249
self .echo_stdin = echo_stdin
250
+ self .catch_exceptions = catch_exceptions
244
251
245
252
def get_default_prog_name (self , cli : Command ) -> str :
246
253
"""Given a command object it will return the default program name
@@ -410,7 +417,7 @@ def invoke(
410
417
args : str | cabc .Sequence [str ] | None = None ,
411
418
input : str | bytes | t .IO [t .Any ] | None = None ,
412
419
env : cabc .Mapping [str , str | None ] | None = None ,
413
- catch_exceptions : bool = True ,
420
+ catch_exceptions : bool | None = None ,
414
421
color : bool = False ,
415
422
** extra : t .Any ,
416
423
) -> Result :
@@ -429,7 +436,8 @@ def invoke(
429
436
:param input: the input data for `sys.stdin`.
430
437
:param env: the environment overrides.
431
438
:param catch_exceptions: Whether to catch any other exceptions than
432
- ``SystemExit``.
439
+ ``SystemExit``. If :data:`None`, the value
440
+ from :class:`CliRunner` is used.
433
441
:param extra: the keyword arguments to pass to :meth:`main`.
434
442
:param color: whether the output should contain color codes. The
435
443
application can still override this explicitly.
@@ -457,6 +465,9 @@ def invoke(
457
465
traceback if available.
458
466
"""
459
467
exc_info = None
468
+ if catch_exceptions is None :
469
+ catch_exceptions = self .catch_exceptions
470
+
460
471
with self .isolation (input = input , env = env , color = color ) as outstreams :
461
472
return_value = None
462
473
exception : BaseException | None = None
0 commit comments