Skip to content

Commit 41fabac

Browse files
fangerertimfel
authored andcommitted
Improve error location reporting in graalpytest.py.
1 parent b7ac9e5 commit 41fabac

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

graalpython/com.oracle.graal.python.test/src/graalpytest.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ def __init__(self):
117117
self.passed = 0
118118
self.failed = 0
119119

120+
def get_useful_frame(self, tb):
121+
from traceback import extract_tb
122+
frame_summaries = extract_tb(tb)
123+
frame_summaries.reverse()
124+
for summary in frame_summaries:
125+
# Skip frame summary entries that refer to this file. These summaries will mostly be there because of the
126+
# assert functions and their location is not interesting.
127+
if summary[0] != __file__:
128+
return summary
129+
130+
120131
def run_safely(self, func, print_immediately=False):
121132
if verbose:
122133
with print_lock:
@@ -132,8 +143,7 @@ def run_safely(self, func, print_immediately=False):
132143
code = func.__code__
133144
_, _, tb = sys.exc_info()
134145
try:
135-
from traceback import extract_tb
136-
filename, line, func, text = extract_tb(tb)[-1]
146+
filename, line, func, text = self.get_useful_frame(tb)
137147
self.exceptions.append(
138148
("In test '%s': %s:%d (%s)" % (code.co_filename, filename, line, func), e)
139149
)

0 commit comments

Comments
 (0)