Skip to content

Commit 714f211

Browse files
authored
Merge pull request #4929 from blueyed/fix-_factorytraceback-offset
Fix line offsets with `ScopeMismatch` errors
2 parents b696666 + d441fa6 commit 714f211

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

changelog/4928.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix line offsets with ``ScopeMismatch`` errors.

src/_pytest/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def _factorytraceback(self):
612612
fs, lineno = getfslineno(factory)
613613
p = self._pyfuncitem.session.fspath.bestrelpath(fs)
614614
args = _format_args(factory)
615-
lines.append("%s:%d: def %s%s" % (p, lineno, factory.__name__, args))
615+
lines.append("%s:%d: def %s%s" % (p, lineno + 1, factory.__name__, args))
616616
return lines
617617

618618
def _getscopeitem(self, scope):

testing/python/fixture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,8 @@ def test_add(arg2):
992992
result.stdout.fnmatch_lines(
993993
[
994994
"*ScopeMismatch*involved factories*",
995-
"* def arg2*",
996-
"* def arg1*",
995+
"test_receives_funcargs_scope_mismatch.py:6: def arg2(arg1)",
996+
"test_receives_funcargs_scope_mismatch.py:2: def arg1()",
997997
"*1 error*",
998998
]
999999
)

0 commit comments

Comments
 (0)