Skip to content

Commit 755ce9b

Browse files
committed
hookspec: improve legacy path deprecation docs
1 parent afc7442 commit 755ce9b

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

changelog/7259.deprecation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``py.path.local`` arguments for hooks have been deprecated. See :ref:`the deprecation note <legacy-path-hooks-deprecated>` for full details.

doc/en/deprecations.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ Below is a complete list of all pytest features which are considered deprecated.
1919
:class:`PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters <warnings>`.
2020

2121

22+
.. _legacy-path-hooks-deprecated:
23+
2224
``py.path.local`` arguments for hooks replaced with ``pathlib.Path``
2325
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2426

25-
In order to support the transition to :mod:`pathlib`, the following hooks now receive additional arguments:
27+
.. deprecated:: 7.0
28+
29+
In order to support the transition from ``py.path.local`` to :mod:`pathlib`, the following hooks now receive additional arguments:
2630

27-
* :func:`pytest_ignore_collect(fspath: pathlib.Path) <_pytest.hookspec.pytest_ignore_collect>`
28-
* :func:`pytest_collect_file(fspath: pathlib.Path) <_pytest.hookspec.pytest_collect_file>`
29-
* :func:`pytest_pycollect_makemodule(fspath: pathlib.Path) <_pytest.hookspec.pytest_pycollect_makemodule>`
30-
* :func:`pytest_report_header(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_header>`
31-
* :func:`pytest_report_collectionfinish(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_collectionfinish>`
31+
* :func:`pytest_ignore_collect(fspath: pathlib.Path) <_pytest.hookspec.pytest_ignore_collect>` instead of ``path``
32+
* :func:`pytest_collect_file(fspath: pathlib.Path) <_pytest.hookspec.pytest_collect_file>` instead of ``path``
33+
* :func:`pytest_pycollect_makemodule(fspath: pathlib.Path) <_pytest.hookspec.pytest_pycollect_makemodule>` instead of ``path``
34+
* :func:`pytest_report_header(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_header>` instead of ``startdir``
35+
* :func:`pytest_report_collectionfinish(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_collectionfinish>` instead of ``startdir``
3236

3337
The accompanying ``py.path.local`` based paths have been deprecated: plugins which manually invoke those hooks should only pass the new ``pathlib.Path`` arguments, and users should change their hook implementations to use the new ``pathlib.Path`` arguments.
3438

src/_pytest/hookspec.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,13 @@ def pytest_ignore_collect(
272272
Stops at first non-None result, see :ref:`firstresult`.
273273
274274
:param pathlib.Path fspath: The path to analyze.
275-
:param LEGACY_PATH path: The path to analyze.
275+
:param LEGACY_PATH path: The path to analyze (deprecated).
276276
:param pytest.Config config: The pytest config object.
277277
278-
.. versionchanged:: 6.3.0
278+
.. versionchanged:: 7.0.0
279279
The ``fspath`` parameter was added as a :class:`pathlib.Path`
280-
equivalent of the ``path`` parameter.
280+
equivalent of the ``path`` parameter. The ``path`` parameter
281+
has been deprecated.
281282
"""
282283

283284

@@ -289,11 +290,12 @@ def pytest_collect_file(
289290
The new node needs to have the specified ``parent`` as a parent.
290291
291292
:param pathlib.Path fspath: The path to analyze.
292-
:param LEGACY_PATH path: The path to collect.
293+
:param LEGACY_PATH path: The path to collect (deprecated).
293294
294-
.. versionchanged:: 6.3.0
295+
.. versionchanged:: 7.0.0
295296
The ``fspath`` parameter was added as a :class:`pathlib.Path`
296-
equivalent of the ``path`` parameter.
297+
equivalent of the ``path`` parameter. The ``path`` parameter
298+
has been deprecated.
297299
"""
298300

299301

@@ -345,11 +347,13 @@ def pytest_pycollect_makemodule(
345347
Stops at first non-None result, see :ref:`firstresult`.
346348
347349
:param pathlib.Path fspath: The path of the module to collect.
348-
:param legacy_path path: The path of the module to collect.
350+
:param LEGACY_PATH path: The path of the module to collect (deprecated).
349351
350-
.. versionchanged:: 6.3.0
352+
.. versionchanged:: 7.0.0
351353
The ``fspath`` parameter was added as a :class:`pathlib.Path`
352354
equivalent of the ``path`` parameter.
355+
356+
The ``path`` parameter has been deprecated in favor of ``fspath``.
353357
"""
354358

355359

@@ -674,7 +678,7 @@ def pytest_report_header(
674678
675679
:param pytest.Config config: The pytest config object.
676680
:param Path startpath: The starting dir.
677-
:param LEGACY_PATH startdir: The starting dir.
681+
:param LEGACY_PATH startdir: The starting dir (deprecated).
678682
679683
.. note::
680684
@@ -689,9 +693,10 @@ def pytest_report_header(
689693
files situated at the tests root directory due to how pytest
690694
:ref:`discovers plugins during startup <pluginorder>`.
691695
692-
.. versionchanged:: 6.3.0
696+
.. versionchanged:: 7.0.0
693697
The ``startpath`` parameter was added as a :class:`pathlib.Path`
694-
equivalent of the ``startdir`` parameter.
698+
equivalent of the ``startdir`` parameter. The ``startdir`` parameter
699+
has been deprecated.
695700
"""
696701

697702

@@ -709,8 +714,8 @@ def pytest_report_collectionfinish(
709714
.. versionadded:: 3.2
710715
711716
:param pytest.Config config: The pytest config object.
712-
:param Path startpath: The starting path.
713-
:param LEGACY_PATH startdir: The starting dir.
717+
:param Path startpath: The starting dir.
718+
:param LEGACY_PATH startdir: The starting dir (deprecated).
714719
:param items: List of pytest items that are going to be executed; this list should not be modified.
715720
716721
.. note::
@@ -720,9 +725,10 @@ def pytest_report_collectionfinish(
720725
If you want to have your line(s) displayed first, use
721726
:ref:`trylast=True <plugin-hookorder>`.
722727
723-
.. versionchanged:: 6.3.0
728+
.. versionchanged:: 7.0.0
724729
The ``startpath`` parameter was added as a :class:`pathlib.Path`
725-
equivalent of the ``startdir`` parameter.
730+
equivalent of the ``startdir`` parameter. The ``startdir`` parameter
731+
has been deprecated.
726732
"""
727733

728734

0 commit comments

Comments
 (0)