Skip to content
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

Highlight my code vs framework code in tracebacks #522

Closed
pytestbot opened this issue Jun 4, 2014 · 10 comments
Closed

Highlight my code vs framework code in tracebacks #522

pytestbot opened this issue Jun 4, 2014 · 10 comments
Labels
topic: tracebacks related to displaying and handling of tracebacks type: enhancement new feature or API change, should be merged into features branch

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Thomas Güttler (BitBucket: thomas-guettler, GitHub: thomas-guettler)


it would be very cool if pytest could highlight my code in tracebacks. This would make it much easier for the developers eyes to find the buggy code line.

In 98% percent of all tracebacks I get, the bug is in my code, not in one of the many external libraries.

Of course it needs some kind of heuristic to decide if a traceback line is from my code or from a library/framework.

Some time ago this was implemented in django, and I liked it very much: You find the important code lines much faster. Since we changed your development style to test driven development, we don't see django tracebacks any more. We use pytest now.

See https://code.djangoproject.com/ticket/11834

This is a feature request. My pytest knowledge is not very good. I think someone else would be much faster.

Which steps should be done to implement this?


@pytestbot pytestbot added the type: enhancement new feature or API change, should be merged into features branch label Jun 15, 2015
@pfctdayelise pfctdayelise added the topic: tracebacks related to displaying and handling of tracebacks label Jul 25, 2015
@Zac-HD
Copy link
Member

Zac-HD commented Oct 20, 2018

I'm closing this issue for two reasons: it's been inactive for four years, but more importantly this kind of traceback management is something that has to be done upstream in frameworks if we're to have any hope of getting it right - and deleting the wrong parts of tracebacks is really really bad for users. For example, both Trio and Hypothesis have recently started trimming their internals from user-facing tracebacks.

(I distinguish here between a "library" which is called by your code, and a "framework" with calls your code. There is no general way to shorten library tracebacks without making them less useful, even upstream.)

@RonnyPfannschmidt
Copy link
Member

I disagree, in particular ssince there days we can partition by distribution

@blueyed
Copy link
Contributor

blueyed commented Apr 8, 2019

@RonnyPfannschmidt
Some input on your idea would be good, since I've started looking into this already (with recent improvements to terminal representation).

@RonnyPfannschmidt
Copy link
Member

@blueyed basically trace-back sections should be collapsed by "distribution" - so sqlalchemy/django/... dont dig in deeper than necessary unless asked for, alternative ux systems could have expand/collapse buttons to view those (like html)

@blueyed
Copy link
Contributor

blueyed commented Apr 13, 2019

Ok. But how to determine which distribution a traceback entry belongs to? Base on the frame's filename only, or is there something more meta in there?
And how to know the "current"/"main" distribution, i.e. the project itself?

@RonnyPfannschmidt
Copy link
Member

current can only reliably be known if its a editable install roughly matching the testdir

distribution metadata has records about belonging files

@pfctdayelise
Copy link
Contributor

I think this is the same idea as #283.

@akx
Copy link

akx commented Feb 7, 2020

Any activity on this? I think a hook for categorizing stack frames would be a nice start (á la #283 (comment)).

I'd further elaborate on that by allowing the hook to return a freeform dict of tags that reporters could use as they'd like, maybe something like

def pytest_tag_traceback_entry(traceback_entry: TracebackEntry) -> Optional[dict]:
   if '/django/' in traceback_entry.path:
       return {'package': 'django'}
   return None  # this hook doesn't know how to categorize this

with multiple hooks' retvals merged together.

A more elaborate/built-in implementation could attempt looking at distribution metadata too...

@blueyed
Copy link
Contributor

blueyed commented Feb 7, 2020

@akx good idea!
Related: #6658 (highlighting of source code in tracebacks).

@RonnyPfannschmidt
Copy link
Member

closing as duplicate of #283

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: tracebacks related to displaying and handling of tracebacks type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

6 participants