Skip to content

Commit aa10bff

Browse files
fix deprecation test for path/fspath hook args
1 parent 53ebe34 commit aa10bff

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

testing/deprecated_test.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import sys
23
import warnings
34
from unittest import mock
45

@@ -157,25 +158,23 @@ def test_raising_unittest_skiptest_during_collection_is_deprecated(
157158
)
158159

159160

160-
def test_hookproxy_warnings_for_fspath(pytestconfig, tmp_path, request):
161+
@pytest.mark.parametrize("hooktype", ["hook", "ihook"])
162+
def test_hookproxy_warnings_for_fspath(tmp_path, hooktype, request):
161163
path = legacy_path(tmp_path)
162164

163165
PATH_WARN_MATCH = r".*path: py\.path\.local\) argument is deprecated, please use \(fspath: pathlib\.Path.*"
166+
if hooktype == "ihook":
167+
hooks = request.node.ihook
168+
else:
169+
hooks = request.config.hook
164170

165171
with pytest.warns(PytestDeprecationWarning, match=PATH_WARN_MATCH) as r:
166-
pytestconfig.hook.pytest_ignore_collect(
167-
config=pytestconfig, path=path, fspath=tmp_path
168-
)
169-
(record,) = r
170-
assert record.filename == __file__
171-
assert record.lineno == 166
172+
l1 = sys._getframe().f_lineno
173+
hooks.pytest_ignore_collect(config=request.config, path=path, fspath=tmp_path)
174+
l2 = sys._getframe().f_lineno
172175

173-
with pytest.warns(PytestDeprecationWarning, match=PATH_WARN_MATCH) as r:
174-
request.node.ihook.pytest_ignore_collect(
175-
config=pytestconfig, path=path, fspath=tmp_path
176-
)
177176
(record,) = r
178177
assert record.filename == __file__
179-
assert record.lineno == 174
180-
pytestconfig.hook.pytest_ignore_collect(config=pytestconfig, fspath=tmp_path)
181-
request.node.ihook.pytest_ignore_collect(config=pytestconfig, fspath=tmp_path)
178+
assert l1 < record.lineno < l2
179+
180+
hooks.pytest_ignore_collect(config=request.config, fspath=tmp_path)

0 commit comments

Comments
 (0)