diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 89de60ffb..6b08341a8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -73,7 +73,8 @@ * -* +* Fixed off-by-one error with lines from ``request.node.warn``. + Thanks to `@blueyed`_ for the PR. * diff --git a/_pytest/main.py b/_pytest/main.py index 31b52c503..2ce9957af 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -267,7 +267,7 @@ class Node(object): if fslocation is None: fslocation = getattr(self, "fspath", None) else: - fslocation = "%s:%s" % fslocation[:2] + fslocation = "%s:%s" % (fslocation[0], fslocation[1] + 1) self.ihook.pytest_logwarning.call_historic(kwargs=dict( code=code, message=message, diff --git a/testing/test_config.py b/testing/test_config.py index f1c762554..1997ddacd 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -525,13 +525,14 @@ class TestWarning: reprec = testdir.inline_run() reprec.assertoutcome(passed=1) - def test_warn_on_test_item_from_request(self, testdir): + def test_warn_on_test_item_from_request(self, testdir, request): testdir.makepyfile(""" import pytest @pytest.fixture def fix(request): request.node.warn("T1", "hello") + def test_hello(fix): pass """) @@ -542,7 +543,7 @@ class TestWarning: result = testdir.runpytest("-rw") result.stdout.fnmatch_lines(""" ===*pytest-warning summary*=== - *WT1*test_warn_on_test_item*:5*hello* + *WT1*test_warn_on_test_item*:7 hello* """) class TestRootdir: