Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminal: fix line offset with skip reports #33

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/2548.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix line offset mismatch with skipped tests in terminal summary.
4 changes: 2 additions & 2 deletions src/_pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def pytest_runtest_makereport(item, call):
# skipped by mark.skipif; change the location of the failure
# to point to the item definition, otherwise it will display
# the location of where the skip exception was raised within pytest
filename, line, reason = rep.longrepr
_, _, reason = rep.longrepr
filename, line = item.location[:2]
rep.longrepr = filename, line, reason
rep.longrepr = filename, line + 1, reason


# called by terminalreporter progress reporting
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ def show_skipped(lines: List[str]) -> None:
if lineno is not None:
lines.append(
"%s [%d] %s:%d: %s"
% (verbose_word, num, fspath, lineno + 1, reason)
% (verbose_word, num, fspath, lineno, reason)
)
else:
lines.append("%s [%d] %s: %s" % (verbose_word, num, fspath, reason))
Expand Down
20 changes: 17 additions & 3 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,23 +731,37 @@ def test_though(self):
def test_skipped_reasons_functional(testdir):
testdir.makepyfile(
test_one="""
import pytest
from conftest import doskip

def setup_function(func):
doskip()

def test_func():
pass

class TestClass(object):
def test_method(self):
doskip()
""",

@pytest.mark.skip("via_decorator")
def test_deco(self):
assert 0
""",
conftest="""
import pytest
import pytest, sys
def doskip():
assert sys._getframe().f_lineno == 3
pytest.skip('test')
""",
)
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


Expand Down