Make it easier to debug CLI errors in pytest

Found this pattern while working on #709
This commit is contained in:
Simon Willison 2025-01-18 14:21:43 -08:00
parent 64179fa9e0
commit f95dd55cda

View file

@ -450,7 +450,13 @@ def prompt(
if extract:
text = extract_first_fenced_code_block(text) or text
print(text)
# List of exceptions that should never be raised in pytest:
except (ValueError, NotImplementedError) as ex:
raise click.ClickException(str(ex))
except Exception as ex:
# All other exceptions should raise in pytest, show to user otherwise
if getattr(sys, "_called_from_test", False):
raise
raise click.ClickException(str(ex))
if isinstance(response, AsyncResponse):