Skip to content

Commit f0b29e2

Browse files
committed
Move Node.fspath to legacypath plugin
1 parent 3861837 commit f0b29e2

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/_pytest/legacypath.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from _pytest.compat import LEGACY_PATH
1616
from _pytest.compat import legacy_path
1717
from _pytest.deprecated import check_ispytest
18+
from _pytest.nodes import Node
1819
from _pytest.pytester import HookRecorder
1920
from _pytest.pytester import RunResult
2021
from _pytest.terminal import TerminalReporter
@@ -389,6 +390,15 @@ def Config__getini_unknown_type(
389390
raise ValueError(f"unknown configuration type: {type}", value)
390391

391392

393+
def Node_fspath(self: Node) -> LEGACY_PATH:
394+
"""(deprecated) returns a legacy_path copy of self.path"""
395+
return legacy_path(self.path)
396+
397+
398+
def Node_fspath_set(self: Node, value: LEGACY_PATH) -> None:
399+
self.path = Path(value)
400+
401+
392402
def pytest_configure(config: pytest.Config) -> None:
393403
mp = pytest.MonkeyPatch()
394404
config._cleanup.append(mp.undo)
@@ -432,3 +442,6 @@ def pytest_configure(config: pytest.Config) -> None:
432442

433443
# Add pathlist configuration type.
434444
mp.setattr(pytest.Config, "_getini_unknown_type", Config__getini_unknown_type)
445+
446+
# Add Node.fspath property.
447+
mp.setattr(Node, "fspath", property(Node_fspath, Node_fspath_set), raising=False)

src/_pytest/nodes.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,6 @@ def __init__(
242242
# Deprecated alias. Was never public. Can be removed in a few releases.
243243
self._store = self.stash
244244

245-
@property
246-
def fspath(self) -> LEGACY_PATH:
247-
"""(deprecated) returns a legacy_path copy of self.path"""
248-
return legacy_path(self.path)
249-
250-
@fspath.setter
251-
def fspath(self, value: LEGACY_PATH) -> None:
252-
self.path = Path(value)
253-
254245
@classmethod
255246
def from_parent(cls, parent: "Node", **kw):
256247
"""Public constructor for Nodes.

testing/test_legacypath.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
from _pytest.pytester import Pytester
66

77

8+
def test_item_fspath(pytester: Pytester) -> None:
9+
pytester.makepyfile("def test_func(): pass")
10+
items, hookrec = pytester.inline_genitems()
11+
assert len(items) == 1
12+
(item,) = items
13+
items2, hookrec = pytester.inline_genitems(item.nodeid)
14+
(item2,) = items2
15+
assert item2.name == item.name
16+
assert item2.fspath == item.fspath # type: ignore[attr-defined]
17+
assert item2.path == item.path
18+
19+
820
def test_testdir_testtmproot(testdir: Testdir) -> None:
921
"""Check test_tmproot is a py.path attribute for backward compatibility."""
1022
assert testdir.test_tmproot.check(dir=1)

0 commit comments

Comments
 (0)