grappa-py / grappa

Behavior-oriented, expressive, human-friendly Python assertion library for the 21st century
http://grappa.rtfd.io
MIT License
134 stars 15 forks source link

Hide traceback lines from library #52

Open ROpdebee opened 5 years ago

ROpdebee commented 5 years ago

Currently the traceback output goes something like this (with pytest --tb=native):

Traceback (most recent call last):
  <stuff in my project>
  <4+ lines inside grappa>
AssertionError: Oops! Something went wrong!
  <grappa custom formatting>

It would be nice if the lines originating from grappa internals could be hidden from the traceback output. pytest has __tracebackhide__ which can be set on a whole module IIRC, but that won't have any effect with --tb=native.

Now, the extent to which this is possible, is probably limited. sys.excepthook might be an option, but should be opt-in as it may override other custom traceback formatters. Also, AFAIK pytest ignores this hook completely and prints out their exceptions on their own. Maybe catch the exception at the top-level of the library, adjust the traceback to remove the library frames, and re-raise? Or a pytest formatter plugin to complement the excepthook?