Skip to content

Commit b7db43c

Browse files
committed
Use pytest test name instead of test function name
1 parent 5fe77df commit b7db43c

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

jumpsuite/jumpsuite.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,16 @@ def format_case(case):
155155
# test_tbline takes priority
156156
interesting_tblines[test_tbline[0]] = test_tbline
157157

158-
for tbline in interesting_tblines.values():
158+
interesting_tblines_iter = iter(interesting_tblines.values())
159+
first_tbline = next(interesting_tblines_iter)
160+
override_name = case.attrib["name"] if is_pytest_parameterized_test(case, first_tbline) else first_tbline[0].name
161+
print(format_tbline(*first_tbline, override_name=override_name))
162+
for tbline in interesting_tblines_iter:
159163
print(format_tbline(*tbline))
160164

165+
def is_pytest_parameterized_test(case, first_tbline):
166+
return case.attrib["name"].startswith(first_tbline[0].name + "[")
167+
161168
def find_last_traceback(detail, case):
162169
lines = []
163170
trailer = detail.splitlines()
@@ -322,11 +329,16 @@ def extract_topmost_tbline(original_lines):
322329
return (line, "", 1)
323330

324331

325-
def format_tbline(tbline, error_line, level=0):
332+
def format_tbline(tbline, error_line, level=0, *, override_name=None):
326333
indent = {0: '', 1: '`- '}[level]
327-
template = "{0.fname}:{0.lineno}:{indent} {0.name} : {error_line} : {0.code_line}"
334+
template = "{0.fname}:{0.lineno}:{indent} {name} : {error_line} : {0.code_line}"
328335
error_line = re.sub('(\d+)(?=:)', r'\1\\', error_line)
329-
return template.format(tbline, indent=indent, error_line=error_line)
336+
return template.format(
337+
tbline,
338+
name=override_name if override_name is not None else tbline.name,
339+
indent=indent,
340+
error_line=error_line,
341+
)
330342

331343

332344
if __name__ == '__main__':

jumpsuite/tests/18.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FAILED. Ran 94 tests in 53.094s (errors=0, failures=2, skipped=0)
2+
/home/user/Projects/myapp/test_common.py:174: test_one[param0] : AssertionError: Trim Trailing Whitespace.................................................Passed : assert len(output.splitlines()) == 8, output
3+
/home/user/Projects/myapp/test_common.py:174: test_one[param1] : AssertionError: Trim Trailing Whitespace.................................................Passed : assert len(output.splitlines()) == 8, output

jumpsuite/tests/18.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<testsuites>
3+
<testsuite name="pytest" errors="0" failures="2" skipped="0" tests="94" time="53.094" timestamp="2022-11-04T15:18:42.836306" hostname="ryan-delta">
4+
<testcase classname="tests.test_common" name="test_one[param0]" time="0.231">
5+
<failure message="AssertionError: Trim Trailing Whitespace.................................................Passed&#10; Fix End of Files.........................................................Passed&#10; Check for added large files..............................................Passed&#10; Sort imports (Python)....................................................Passed&#10; &#10;assert 4 == 8&#10; + where 4 = len(['Trim Trailing Whitespace.................................................Passed', 'Fix End of Files................................................Passed', 'Sort imports (Python)....................................................Passed'])&#10; + where ['Trim Trailing Whitespace.................................................Passed', 'Fix End of Files................................................Passed', 'Sort imports (Python)....................................................Passed'] = &lt;built-in method splitlines of str object at 0x7f72449bea30&gt;()&#10; + where &lt;built-in method splitlines of str object at 0x7f72449bea30&gt; = 'Trim Trailing Whitespace.................................................Passed\nFix End of Files....................................................Passed\nSort imports (Python)....................................................Passed\n'.splitlines">Traceback (most recent call last):
6+
File "/home/user/Projects/myapp/test_common.py", line 174, in test_one
7+
assert len(output.splitlines()) == 8, output
8+
AssertionError: Trim Trailing Whitespace.................................................Passed
9+
Fix End of Files.........................................................Passed
10+
Check for added large files..............................................Passed
11+
Sort imports (Python)....................................................Passed
12+
13+
assert 4 == 8
14+
+ where 4 = len(['Trim Trailing Whitespace.................................................Passed', 'Fix End of Files................................................Passed', 'Sort imports (Python)....................................................Passed'])
15+
+ where ['Trim Trailing Whitespace.................................................Passed', 'Fix End of Files................................................Passed', 'Sort imports (Python)....................................................Passed'] = &lt;built-in method splitlines of str object at 0x7f72449bea30&gt;()
16+
+ where &lt;built-in method splitlines of str object at 0x7f72449bea30&gt; = 'Trim Trailing Whitespace.................................................Passed\nFix End of Files....................................................Passed\nSort imports (Python)....................................................Passed\n'.splitlines
17+
</failure>
18+
</testcase>
19+
<testcase classname="tests.test_common" name="test_one[param1]" time="0.274">
20+
<failure message="AssertionError: Trim Trailing Whitespace.................................................Passed&#10; Fix End of Files.........................................................Passed&#10; Check for added large files..............................................Passed&#10; Sort imports (Python)....................................................Passed&#10; &#10;assert 4 == 8&#10; + where 4 = len(['Trim Trailing Whitespace.................................................Passed', 'Fix End of Files................................................Passed', 'Sort imports (Python)....................................................Passed'])&#10; + where ['Trim Trailing Whitespace.................................................Passed', 'Fix End of Files................................................Passed', 'Sort imports (Python)....................................................Passed'] = &lt;built-in method splitlines of str object at 0x7f72449bf1b0&gt;()&#10; + where &lt;built-in method splitlines of str object at 0x7f72449bf1b0&gt; = 'Trim Trailing Whitespace.................................................Passed\nFix End of Files....................................................Passed\nSort imports (Python)....................................................Passed\n'.splitlines">Traceback (most recent call last):
21+
File "/home/user/Projects/myapp/test_common.py", line 174, in test_one
22+
assert len(output.splitlines()) == 8, output
23+
AssertionError: Trim Trailing Whitespace.................................................Passed
24+
Fix End of Files.........................................................Passed
25+
Check for added large files..............................................Passed
26+
Sort imports (Python)....................................................Passed
27+
28+
assert 4 == 8
29+
+ where 4 = len(['Trim Trailing Whitespace.................................................Passed', 'Fix End of Files................................................Passed', 'Sort imports (Python)....................................................Passed'])
30+
+ where ['Trim Trailing Whitespace.................................................Passed', 'Fix End of Files................................................Passed', 'Sort imports (Python)....................................................Passed'] = &lt;built-in method splitlines of str object at 0x7f72449bf1b0&gt;()
31+
+ where &lt;built-in method splitlines of str object at 0x7f72449bf1b0&gt; = 'Trim Trailing Whitespace.................................................Passed\nFix End of Files....................................................Passed\nSort imports (Python)....................................................Passed\n'.splitlines
32+
</failure>
33+
</testcase>
34+
</testsuite>
35+
</testsuites>

0 commit comments

Comments
 (0)