|
28 | 28 | from _pytest.config import Config |
29 | 29 | from _pytest.config import ConftestImportFailure |
30 | 30 | from _pytest.deprecated import FSCOLLECTOR_GETHOOKPROXY_ISINITPATH |
| 31 | +from _pytest.deprecated import NODE_CTOR_FSPATH_ARG |
31 | 32 | from _pytest.mark.structures import Mark |
32 | 33 | from _pytest.mark.structures import MarkDecorator |
33 | 34 | from _pytest.mark.structures import NodeKeywords |
@@ -101,7 +102,18 @@ def _check_path(path: Path, fspath: LEGACY_PATH) -> None: |
101 | 102 | ) |
102 | 103 |
|
103 | 104 |
|
104 | | -def _imply_path(path: Optional[Path], fspath: Optional[LEGACY_PATH]) -> Path: |
| 105 | +def _imply_path( |
| 106 | + node_type: Type["Node"], |
| 107 | + path: Optional[Path], |
| 108 | + fspath: Optional[LEGACY_PATH], |
| 109 | +) -> Path: |
| 110 | + if fspath is not None: |
| 111 | + warnings.warn( |
| 112 | + NODE_CTOR_FSPATH_ARG.format( |
| 113 | + node_type_name=node_type.__name__, |
| 114 | + ), |
| 115 | + stacklevel=3, |
| 116 | + ) |
105 | 117 | if path is not None: |
106 | 118 | if fspath is not None: |
107 | 119 | _check_path(path, fspath) |
@@ -196,7 +208,7 @@ def __init__( |
196 | 208 | #: Filesystem path where this node was collected from (can be None). |
197 | 209 | if path is None and fspath is None: |
198 | 210 | path = getattr(parent, "path", None) |
199 | | - self.path = _imply_path(path, fspath=fspath) |
| 211 | + self.path = _imply_path(type(self), path, fspath=fspath) |
200 | 212 |
|
201 | 213 | # The explicit annotation is to avoid publicly exposing NodeKeywords. |
202 | 214 | #: Keywords/markers collected from all scopes. |
@@ -573,7 +585,7 @@ def __init__( |
573 | 585 | assert path is None |
574 | 586 | path = path_or_parent |
575 | 587 |
|
576 | | - path = _imply_path(path, fspath=fspath) |
| 588 | + path = _imply_path(type(self), path, fspath=fspath) |
577 | 589 | if name is None: |
578 | 590 | name = path.name |
579 | 591 | if parent is not None and parent.path != path: |
|
0 commit comments