Fix line offsets with `ScopeMismatch` errors

Fixes https://github.com/pytest-dev/pytest/issues/4928.
This commit is contained in:
Daniel Hahler 2019-03-15 02:47:06 +01:00
parent 158432217c
commit d441fa66fe
3 changed files with 4 additions and 3 deletions

View File

@ -0,0 +1 @@
Fix line offsets with ``ScopeMismatch`` errors.

View File

@ -612,7 +612,7 @@ class FixtureRequest(FuncargnamesCompatAttr):
fs, lineno = getfslineno(factory) fs, lineno = getfslineno(factory)
p = self._pyfuncitem.session.fspath.bestrelpath(fs) p = self._pyfuncitem.session.fspath.bestrelpath(fs)
args = _format_args(factory) args = _format_args(factory)
lines.append("%s:%d: def %s%s" % (p, lineno, factory.__name__, args)) lines.append("%s:%d: def %s%s" % (p, lineno + 1, factory.__name__, args))
return lines return lines
def _getscopeitem(self, scope): def _getscopeitem(self, scope):

View File

@ -992,8 +992,8 @@ class TestFixtureUsages(object):
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
"*ScopeMismatch*involved factories*", "*ScopeMismatch*involved factories*",
"* def arg2*", "test_receives_funcargs_scope_mismatch.py:6: def arg2(arg1)",
"* def arg1*", "test_receives_funcargs_scope_mismatch.py:2: def arg1()",
"*1 error*", "*1 error*",
] ]
) )