1
1
"""Hook specifications for pytest plugins which are invoked by pytest itself
2
2
and by builtin plugins."""
3
+ from pathlib import Path
3
4
from typing import Any
4
5
from typing import Dict
5
6
from typing import List
@@ -261,27 +262,39 @@ def pytest_collection_finish(session: "Session") -> None:
261
262
262
263
263
264
@hookspec (firstresult = True )
264
- def pytest_ignore_collect (path : py .path .local , config : "Config" ) -> Optional [bool ]:
265
+ def pytest_ignore_collect (
266
+ fspath : Path , path : py .path .local , config : "Config"
267
+ ) -> Optional [bool ]:
265
268
"""Return True to prevent considering this path for collection.
266
269
267
270
This hook is consulted for all files and directories prior to calling
268
271
more specific hooks.
269
272
270
273
Stops at first non-None result, see :ref:`firstresult`.
271
274
275
+ :param pathlib.Path fspath: The path to analyze.
272
276
:param py.path.local path: The path to analyze.
273
277
:param _pytest.config.Config config: The pytest config object.
278
+
279
+ .. versionchanged:: 6.3.0
280
+ The ``fspath`` parameter was added as a :class:`pathlib.Path`
281
+ equivalent of the ``path`` parameter.
274
282
"""
275
283
276
284
277
285
def pytest_collect_file (
278
- path : py .path .local , parent : "Collector"
286
+ fspath : Path , path : py .path .local , parent : "Collector"
279
287
) -> "Optional[Collector]" :
280
288
"""Create a Collector for the given path, or None if not relevant.
281
289
282
290
The new node needs to have the specified ``parent`` as a parent.
283
291
292
+ :param pathlib.Path fspath: The path to analyze.
284
293
:param py.path.local path: The path to collect.
294
+
295
+ .. versionchanged:: 6.3.0
296
+ The ``fspath`` parameter was added as a :class:`pathlib.Path`
297
+ equivalent of the ``path`` parameter.
285
298
"""
286
299
287
300
@@ -321,7 +334,9 @@ def pytest_make_collect_report(collector: "Collector") -> "Optional[CollectRepor
321
334
322
335
323
336
@hookspec (firstresult = True )
324
- def pytest_pycollect_makemodule (path : py .path .local , parent ) -> Optional ["Module" ]:
337
+ def pytest_pycollect_makemodule (
338
+ fspath : Path , path : py .path .local , parent
339
+ ) -> Optional ["Module" ]:
325
340
"""Return a Module collector or None for the given path.
326
341
327
342
This hook will be called for each matching test module path.
@@ -330,7 +345,12 @@ def pytest_pycollect_makemodule(path: py.path.local, parent) -> Optional["Module
330
345
331
346
Stops at first non-None result, see :ref:`firstresult`.
332
347
333
- :param py.path.local path: The path of module to collect.
348
+ :param pathlib.Path fspath: The path of the module to collect.
349
+ :param py.path.local path: The path of the module to collect.
350
+
351
+ .. versionchanged:: 6.3.0
352
+ The ``fspath`` parameter was added as a :class:`pathlib.Path`
353
+ equivalent of the ``path`` parameter.
334
354
"""
335
355
336
356
@@ -653,11 +673,12 @@ def pytest_assertion_pass(item: "Item", lineno: int, orig: str, expl: str) -> No
653
673
654
674
655
675
def pytest_report_header (
656
- config : "Config" , startdir : py .path .local
676
+ config : "Config" , startpath : Path , startdir : py .path .local
657
677
) -> Union [str , List [str ]]:
658
678
"""Return a string or list of strings to be displayed as header info for terminal reporting.
659
679
660
680
:param _pytest.config.Config config: The pytest config object.
681
+ :param Path startpath: The starting dir.
661
682
:param py.path.local startdir: The starting dir.
662
683
663
684
.. note::
@@ -672,11 +693,15 @@ def pytest_report_header(
672
693
This function should be implemented only in plugins or ``conftest.py``
673
694
files situated at the tests root directory due to how pytest
674
695
:ref:`discovers plugins during startup <pluginorder>`.
696
+
697
+ .. versionchanged:: 6.3.0
698
+ The ``startpath`` parameter was added as a :class:`pathlib.Path`
699
+ equivalent of the ``startdir`` parameter.
675
700
"""
676
701
677
702
678
703
def pytest_report_collectionfinish (
679
- config : "Config" , startdir : py .path .local , items : Sequence ["Item" ],
704
+ config : "Config" , startpath : Path , startdir : py .path .local , items : Sequence ["Item" ],
680
705
) -> Union [str , List [str ]]:
681
706
"""Return a string or list of strings to be displayed after collection
682
707
has finished successfully.
@@ -686,6 +711,7 @@ def pytest_report_collectionfinish(
686
711
.. versionadded:: 3.2
687
712
688
713
:param _pytest.config.Config config: The pytest config object.
714
+ :param Path startpath: The starting path.
689
715
:param py.path.local startdir: The starting dir.
690
716
:param items: List of pytest items that are going to be executed; this list should not be modified.
691
717
@@ -695,6 +721,10 @@ def pytest_report_collectionfinish(
695
721
ran before it.
696
722
If you want to have your line(s) displayed first, use
697
723
:ref:`trylast=True <plugin-hookorder>`.
724
+
725
+ .. versionchanged:: 6.3.0
726
+ The ``startpath`` parameter was added as a :class:`pathlib.Path`
727
+ equivalent of the ``startdir`` parameter.
698
728
"""
699
729
700
730
0 commit comments