tests/misc/sys_settrace_features.py: Fix to run on newer CPython.

This test was failing on CPython 3.11 as it now emits `0` as the line
number for the "call" event corresponding to import, where as in 3.6 it had
`1` as the line number.

We maintain the old behavior, but in order to make this test pass on both
CPython versions, the trace handler now converts the `0` to a `1`.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2023-08-23 13:13:59 +10:00 committed by Damien George
parent 1dedb65e64
commit 4a3fdc0e76

View File

@ -22,7 +22,9 @@ def print_stacktrace(frame, level=0):
frame.f_code.co_name,
# Keep just the filename.
"sys_settrace_" + frame.f_code.co_filename.split("sys_settrace_")[-1],
frame.f_lineno,
max(
1, frame.f_lineno
), # CPython 3.11 emits `0` where CPython 3.6 emits `1` for the "call" event corresponding to import.
)
)