From d441fa66fea052d04364acb6fc67c3b3cc0217c0 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 15 Mar 2019 02:47:06 +0100 Subject: [PATCH] Fix line offsets with `ScopeMismatch` errors Fixes https://github.com/pytest-dev/pytest/issues/4928. --- changelog/4928.bugfix.rst | 1 + src/_pytest/fixtures.py | 2 +- testing/python/fixture.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelog/4928.bugfix.rst diff --git a/changelog/4928.bugfix.rst b/changelog/4928.bugfix.rst new file mode 100644 index 000000000..8959efacb --- /dev/null +++ b/changelog/4928.bugfix.rst @@ -0,0 +1 @@ +Fix line offsets with ``ScopeMismatch`` errors. diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index b2ad9aae3..5dc803d66 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -612,7 +612,7 @@ class FixtureRequest(FuncargnamesCompatAttr): fs, lineno = getfslineno(factory) p = self._pyfuncitem.session.fspath.bestrelpath(fs) 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 def _getscopeitem(self, scope): diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 3d557cec8..53df1990b 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -992,8 +992,8 @@ class TestFixtureUsages(object): result.stdout.fnmatch_lines( [ "*ScopeMismatch*involved factories*", - "* def arg2*", - "* def arg1*", + "test_receives_funcargs_scope_mismatch.py:6: def arg2(arg1)", + "test_receives_funcargs_scope_mismatch.py:2: def arg1()", "*1 error*", ] )