-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use rich traceback #996
Comments
Mmh, after a short look at „rich / rich trackbacks“:
POTENTIALlY AFFECTED:
EXPERIMENT (for you):
HINTS:
QUESTIONS:
Explore how far you get with that (and what other stumbling stones are that lay in the way). |
Thanks for the quick review and digging into it a little.
I've already tried that, but it doesn't have any effect. I could actually except my own assert and then just print it with rich. However, I'm more looking for the I may do an experiment with a rich formatter ... I'll keep you posted. |
Inspired by "Debug-on-Error (in Case of Step Failures)", import behave
from behave.model import Step
from rich.console import Console
from rich.traceback import Traceback
def print_rich_traceback(step: Step):
"""
Print an exception traceback from a failed step
using https://pypi.org/project/rich/
To be used in a step hook like::
def after_step(context, step):
if step.status == "failed":
print_rich_traceback(step)
...
"""
if not (getattr(step, "exception", False) and getattr(step, "exc_traceback", False)):
return
traceback = Traceback.from_exception(
type(step.exception),
step.exception,
step.exc_traceback,
show_locals=True,
suppress=[behave],
)
# Forcing terminal on the console, because behave captures output.
# TODO: auto-detect this (from context.config?)
console = Console(force_terminal=True)
console.print(traceback) |
At the moment behave handles all assertion exceptions, therefore preventing someone to use rich tracebacks.
It would be awesome if rich tracebacks and behave would work together somehow.
In the meantime, is it possible to overwrite how exceptions are rendered in behave?
The text was updated successfully, but these errors were encountered: