nodes: deprecate fspath arguments to node constructors
This is unfortunately a dependency on `py.path` which cannot be moved to an external plugins or eased in any way, so has to be deprecated in order for pytest to be able to eventually remove the dependency on `py`.
This commit is contained in:
@@ -28,6 +28,7 @@ from _pytest.compat import legacy_path
|
||||
from _pytest.config import Config
|
||||
from _pytest.config import ConftestImportFailure
|
||||
from _pytest.deprecated import FSCOLLECTOR_GETHOOKPROXY_ISINITPATH
|
||||
from _pytest.deprecated import NODE_CTOR_FSPATH_ARG
|
||||
from _pytest.mark.structures import Mark
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
from _pytest.mark.structures import NodeKeywords
|
||||
@@ -101,7 +102,18 @@ def _check_path(path: Path, fspath: LEGACY_PATH) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _imply_path(path: Optional[Path], fspath: Optional[LEGACY_PATH]) -> Path:
|
||||
def _imply_path(
|
||||
node_type: Type["Node"],
|
||||
path: Optional[Path],
|
||||
fspath: Optional[LEGACY_PATH],
|
||||
) -> Path:
|
||||
if fspath is not None:
|
||||
warnings.warn(
|
||||
NODE_CTOR_FSPATH_ARG.format(
|
||||
node_type_name=node_type.__name__,
|
||||
),
|
||||
stacklevel=3,
|
||||
)
|
||||
if path is not None:
|
||||
if fspath is not None:
|
||||
_check_path(path, fspath)
|
||||
@@ -196,7 +208,7 @@ class Node(metaclass=NodeMeta):
|
||||
#: Filesystem path where this node was collected from (can be None).
|
||||
if path is None and fspath is None:
|
||||
path = getattr(parent, "path", None)
|
||||
self.path = _imply_path(path, fspath=fspath)
|
||||
self.path = _imply_path(type(self), path, fspath=fspath)
|
||||
|
||||
# The explicit annotation is to avoid publicly exposing NodeKeywords.
|
||||
#: Keywords/markers collected from all scopes.
|
||||
@@ -573,7 +585,7 @@ class FSCollector(Collector):
|
||||
assert path is None
|
||||
path = path_or_parent
|
||||
|
||||
path = _imply_path(path, fspath=fspath)
|
||||
path = _imply_path(type(self), path, fspath=fspath)
|
||||
if name is None:
|
||||
name = path.name
|
||||
if parent is not None and parent.path != path:
|
||||
|
||||
Reference in New Issue
Block a user