terminal: fix line offset with skip reports

The original fix in https://github.com/pytest-dev/pytest/pull/2548 was
wrong, and was likely meant to fix the use with decorators instead,
which this does now (while reverting 869eed9898).
This commit is contained in:
Daniel Hahler 2019-10-29 12:18:07 +01:00
parent 0225cb37c0
commit 6d2cabae57
4 changed files with 21 additions and 6 deletions

View File

@ -0,0 +1 @@
Fix line offset mismatch with skipped tests in terminal summary.

View File

@ -161,9 +161,9 @@ def pytest_runtest_makereport(item, call):
# skipped by mark.skipif; change the location of the failure # skipped by mark.skipif; change the location of the failure
# to point to the item definition, otherwise it will display # to point to the item definition, otherwise it will display
# the location of where the skip exception was raised within pytest # the location of where the skip exception was raised within pytest
filename, line, reason = rep.longrepr _, _, reason = rep.longrepr
filename, line = item.location[:2] filename, line = item.location[:2]
rep.longrepr = filename, line, reason rep.longrepr = filename, line + 1, reason
# called by terminalreporter progress reporting # called by terminalreporter progress reporting

View File

@ -954,7 +954,7 @@ class TerminalReporter:
if lineno is not None: if lineno is not None:
lines.append( lines.append(
"%s [%d] %s:%d: %s" "%s [%d] %s:%d: %s"
% (verbose_word, num, fspath, lineno + 1, reason) % (verbose_word, num, fspath, lineno, reason)
) )
else: else:
lines.append("%s [%d] %s: %s" % (verbose_word, num, fspath, reason)) lines.append("%s [%d] %s: %s" % (verbose_word, num, fspath, reason))

View File

@ -731,23 +731,37 @@ def test_skipif_class(testdir):
def test_skipped_reasons_functional(testdir): def test_skipped_reasons_functional(testdir):
testdir.makepyfile( testdir.makepyfile(
test_one=""" test_one="""
import pytest
from conftest import doskip from conftest import doskip
def setup_function(func): def setup_function(func):
doskip() doskip()
def test_func(): def test_func():
pass pass
class TestClass(object): class TestClass(object):
def test_method(self): def test_method(self):
doskip() doskip()
""",
@pytest.mark.skip("via_decorator")
def test_deco(self):
assert 0
""",
conftest=""" conftest="""
import pytest import pytest, sys
def doskip(): def doskip():
assert sys._getframe().f_lineno == 3
pytest.skip('test') pytest.skip('test')
""", """,
) )
result = testdir.runpytest("-rs") result = testdir.runpytest("-rs")
result.stdout.fnmatch_lines(["*SKIP*2*conftest.py:4: test"]) result.stdout.fnmatch_lines_random(
[
"SKIPPED [[]2[]] */conftest.py:4: test",
"SKIPPED [[]1[]] test_one.py:14: via_decorator",
]
)
assert result.ret == 0 assert result.ret == 0