Skip to content

Commit deb5b5b

Browse files
fix #8371: fix stack-level
1 parent bad1963 commit deb5b5b

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/_pytest/config/compat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def fixed_hook(**kw):
4949
warnings.warn(
5050
HOOK_LEGACY_PATH_ARG.format(
5151
pylib_path_arg=fspath_var, pathlib_path_arg=path_var
52-
)
52+
),
53+
stacklevel=2,
5354
)
5455
path_value, fspath_value = _imply_path(path_value, fspath_value)
5556
kw[path_var] = path_value

testing/deprecated_test.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,22 @@ def test_raising_unittest_skiptest_during_collection_is_deprecated(
160160
def test_hookproxy_warnings_for_fspath(pytestconfig, tmp_path, request):
161161
path = legacy_path(tmp_path)
162162

163-
with pytest.warns(
164-
PytestDeprecationWarning,
165-
match="path : py.path.local is deprecated, please use fspath : pathlib.Path",
166-
):
163+
PATH_WARN_MATCH = r".*path: py\.path\.local\) argument is deprecated, please use \(fspath: pathlib\.Path.*"
164+
165+
with pytest.warns(PytestDeprecationWarning, match=PATH_WARN_MATCH) as r:
167166
pytestconfig.hook.pytest_ignore_collect(
168167
config=pytestconfig, path=path, fspath=tmp_path
169168
)
170-
with pytest.warns(
171-
PytestDeprecationWarning,
172-
match="path : py.path.local is deprecated, please use fspath : pathlib.Path",
173-
):
169+
(record,) = r
170+
assert record.filename == __file__
171+
assert record.lineno == 166
172+
173+
with pytest.warns(PytestDeprecationWarning, match=PATH_WARN_MATCH) as r:
174174
request.node.ihook.pytest_ignore_collect(
175175
config=pytestconfig, path=path, fspath=tmp_path
176176
)
177-
177+
(record,) = r
178+
assert record.filename == __file__
179+
assert record.lineno == 174
178180
pytestconfig.hook.pytest_ignore_collect(config=pytestconfig, fspath=tmp_path)
179181
request.node.ihook.pytest_ignore_collect(config=pytestconfig, fspath=tmp_path)

0 commit comments

Comments
 (0)