Skip to content

Commit ca59579

Browse files
authored
Merge pull request #1806 from blueyed/fix-off-by-one-error-with-warnings
Fix off-by-one error with lines from request.node.warn
2 parents d58a8e3 + 16cb5d0 commit ca59579

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373

7474
*
7575

76-
*
76+
* Fixed off-by-one error with lines from ``request.node.warn``.
77+
Thanks to `@blueyed`_ for the PR.
7778

7879
*
7980

_pytest/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def warn(self, code, message):
267267
if fslocation is None:
268268
fslocation = getattr(self, "fspath", None)
269269
else:
270-
fslocation = "%s:%s" % fslocation[:2]
270+
fslocation = "%s:%s" % (fslocation[0], fslocation[1] + 1)
271271

272272
self.ihook.pytest_logwarning.call_historic(kwargs=dict(
273273
code=code, message=message,

testing/test_config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,14 @@ def test_proper(pytestconfig):
525525
reprec = testdir.inline_run()
526526
reprec.assertoutcome(passed=1)
527527

528-
def test_warn_on_test_item_from_request(self, testdir):
528+
def test_warn_on_test_item_from_request(self, testdir, request):
529529
testdir.makepyfile("""
530530
import pytest
531531
532532
@pytest.fixture
533533
def fix(request):
534534
request.node.warn("T1", "hello")
535+
535536
def test_hello(fix):
536537
pass
537538
""")
@@ -542,7 +543,7 @@ def test_hello(fix):
542543
result = testdir.runpytest("-rw")
543544
result.stdout.fnmatch_lines("""
544545
===*pytest-warning summary*===
545-
*WT1*test_warn_on_test_item*:5*hello*
546+
*WT1*test_warn_on_test_item*:7 hello*
546547
""")
547548

548549
class TestRootdir:

0 commit comments

Comments
 (0)