|
1 | 1 | import re
|
| 2 | +import sys |
2 | 3 | import warnings
|
3 | 4 | from unittest import mock
|
4 | 5 |
|
@@ -157,25 +158,23 @@ def test_raising_unittest_skiptest_during_collection_is_deprecated(
|
157 | 158 | )
|
158 | 159 |
|
159 | 160 |
|
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): |
161 | 163 | path = legacy_path(tmp_path)
|
162 | 164 |
|
163 | 165 | 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 |
164 | 170 |
|
165 | 171 | 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 |
172 | 175 |
|
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 |
| - ) |
177 | 176 | (record,) = r
|
178 | 177 | 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