pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
12.01k stars 2.67k forks source link

PEP-657 enhanced error locations in pytest tracebacks #10224

Open davidszotten opened 2 years ago

davidszotten commented 2 years ago

Hi. Are there any plans to support PEP-657 style enhanced tracebacks when on py 3.11? with some pointers i'd be happy to look at implemetation

nicoddemus commented 2 years ago

Hi @davidszotten,

There's https://github.com/pytest-dev/pytest/pull/10209 open to at least fall back to native traceback printing temporarily, https://github.com/pytest-dev/pytest/issues/9159 tracks the full support.

davidszotten commented 2 years ago

hi @nicoddemus , thanks for the quick reply. just to be clear, i'm talking about

https://docs.python.org/3.11/whatsnew/3.11.html#enhanced-error-locations-in-tracebacks

Traceback (most recent call last):
  File "distance.py", line 11, in <module>
    print(manhattan_distance(p1, p2))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "distance.py", line 6, in manhattan_distance
    return abs(point_1.x - point_2.x) + abs(point_1.y - point_2.y)
                           ^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'x'

not exception groups. or are the two tied together?

nicoddemus commented 2 years ago

🤦 Sorry indeed they are not related, sorry for the confusion.

I don't think we have any plans regarding that (a quick search did not turn out much), but this is something we should definitely look into.

nicoddemus commented 2 years ago

Btw you asked for pointers: the traceback printing code starts in ExceptionRepr.toterminal, it should be possible to figure out/understand the code from there.

Zac-HD commented 2 years ago

You can of course get the native representation with pytest --tb=native, but it would indeed be good to support the more precise locations in long, short, and auto modes too 🙂