Skip to content

Commit aed97ea

Browse files
committed
terminal: fix line offset with skip reports
The original fix in #2548 was wrong, and was likely meant to fix the use with decorators instead, which this does now (while reverting 869eed9).
1 parent 0225cb3 commit aed97ea

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

changelog/2548.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix line offset mismatch with skipped tests in terminal summary.

src/_pytest/skipping.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ def pytest_runtest_makereport(item, call):
161161
# skipped by mark.skipif; change the location of the failure
162162
# to point to the item definition, otherwise it will display
163163
# the location of where the skip exception was raised within pytest
164-
filename, line, reason = rep.longrepr
164+
_, _, reason = rep.longrepr
165165
filename, line = item.location[:2]
166-
rep.longrepr = filename, line, reason
166+
rep.longrepr = filename, line + 1, reason
167167

168168

169169
# called by terminalreporter progress reporting

src/_pytest/terminal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ def show_skipped(lines: List[str]) -> None:
954954
if lineno is not None:
955955
lines.append(
956956
"%s [%d] %s:%d: %s"
957-
% (verbose_word, num, fspath, lineno + 1, reason)
957+
% (verbose_word, num, fspath, lineno, reason)
958958
)
959959
else:
960960
lines.append("%s [%d] %s: %s" % (verbose_word, num, fspath, reason))

testing/test_skipping.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,23 +731,37 @@ def test_though(self):
731731
def test_skipped_reasons_functional(testdir):
732732
testdir.makepyfile(
733733
test_one="""
734+
import pytest
734735
from conftest import doskip
736+
735737
def setup_function(func):
736738
doskip()
739+
737740
def test_func():
738741
pass
742+
739743
class TestClass(object):
740744
def test_method(self):
741745
doskip()
742-
""",
746+
747+
@pytest.mark.skip("via_decorator")
748+
def test_deco(self):
749+
assert 0
750+
""",
743751
conftest="""
744-
import pytest
752+
import pytest, sys
745753
def doskip():
754+
assert sys._getframe().f_lineno == 3
746755
pytest.skip('test')
747756
""",
748757
)
749758
result = testdir.runpytest("-rs")
750-
result.stdout.fnmatch_lines(["*SKIP*2*conftest.py:4: test"])
759+
result.stdout.fnmatch_lines(
760+
[
761+
"SKIPPED [[]2[]] */conftest.py:4: test",
762+
"SKIPPED [[]1[]] test_one.py:14: via_decorator",
763+
]
764+
)
751765
assert result.ret == 0
752766

753767

0 commit comments

Comments
 (0)