Skip to content

Commit f0c7043

Browse files
committed
Remove/replace some more unnecessary uses of py.path
1 parent a03ee02 commit f0c7043

File tree

17 files changed

+75
-78
lines changed

17 files changed

+75
-78
lines changed

doc/en/example/nonpython/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
import pytest
33

44

5-
def pytest_collect_file(parent, path):
6-
if path.ext == ".yaml" and path.basename.startswith("test"):
7-
return YamlFile.from_parent(parent, fspath=path)
5+
def pytest_collect_file(parent, fspath):
6+
if fspath.suffix == ".yaml" and fspath.name.startswith("test"):
7+
return YamlFile.from_parent(parent, path=fspath)
88

99

1010
class YamlFile(pytest.File):
1111
def collect(self):
1212
# We need a yaml parser, e.g. PyYAML.
1313
import yaml
1414

15-
raw = yaml.safe_load(self.fspath.open())
15+
raw = yaml.safe_load(self.path.open())
1616
for name, spec in sorted(raw.items()):
1717
yield YamlItem.from_parent(self, name=name, spec=spec)
1818

src/_pytest/doctest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from _pytest._code.code import ReprFileLocation
2929
from _pytest._code.code import TerminalRepr
3030
from _pytest._io import TerminalWriter
31-
from _pytest.compat import LEGACY_PATH
3231
from _pytest.compat import legacy_path
3332
from _pytest.compat import safe_getattr
3433
from _pytest.config import Config
@@ -122,7 +121,6 @@ def pytest_unconfigure() -> None:
122121

123122
def pytest_collect_file(
124123
fspath: Path,
125-
path: LEGACY_PATH,
126124
parent: Collector,
127125
) -> Optional[Union["DoctestModule", "DoctestTextfile"]]:
128126
config = parent.config

src/_pytest/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class Session(nodes.FSCollector):
465465
def __init__(self, config: Config) -> None:
466466
super().__init__(
467467
path=config.rootpath,
468-
fspath=config.rootdir,
468+
fspath=None,
469469
parent=None,
470470
config=config,
471471
session=self,

src/_pytest/pytester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def copy_example(self, name: Optional[str] = None) -> Path:
912912
example_dir = self._request.config.getini("pytester_example_dir")
913913
if example_dir is None:
914914
raise ValueError("pytester_example_dir is unset, can't copy examples")
915-
example_dir = Path(str(self._request.config.rootdir)) / example_dir
915+
example_dir = self._request.config.rootpath / example_dir
916916

917917
for extra_element in self._request.node.iter_markers("pytester_example_path"):
918918
assert extra_element.args

src/_pytest/python.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ def path_matches_patterns(path: Path, patterns: Iterable[str]) -> bool:
210210
return any(fnmatch_ex(pattern, path) for pattern in patterns)
211211

212212

213-
def pytest_pycollect_makemodule(fspath: Path, path: LEGACY_PATH, parent) -> "Module":
213+
def pytest_pycollect_makemodule(fspath: Path, parent) -> "Module":
214214
if fspath.name == "__init__.py":
215-
pkg: Package = Package.from_parent(parent, fspath=path)
215+
pkg: Package = Package.from_parent(parent, path=fspath)
216216
return pkg
217-
mod: Module = Module.from_parent(parent, fspath=path)
217+
mod: Module = Module.from_parent(parent, path=fspath)
218218
return mod
219219

220220

@@ -691,7 +691,7 @@ def _collectfile(
691691
assert (
692692
fspath.is_file()
693693
), "{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})".format(
694-
path, fspath.is_dir(), fspath.exists(), fspath.is_symlink()
694+
fspath, fspath.is_dir(), fspath.exists(), fspath.is_symlink()
695695
)
696696
ihook = self.session.gethookproxy(fspath)
697697
if not self.session.isinitpath(fspath):

testing/acceptance_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ def runtest(self):
304304
class MyCollector(pytest.File):
305305
def collect(self):
306306
return [MyItem.from_parent(name="xyz", parent=self)]
307-
def pytest_collect_file(path, parent):
308-
if path.basename.startswith("conftest"):
309-
return MyCollector.from_parent(fspath=path, parent=parent)
307+
def pytest_collect_file(fspath, parent):
308+
if fspath.name.startswith("conftest"):
309+
return MyCollector.from_parent(path=fspath, parent=parent)
310310
"""
311311
)
312312
result = pytester.runpytest(c.name + "::" + "xyz")

testing/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ def dummy_yaml_custom_test(pytester: Pytester):
114114
"""
115115
import pytest
116116
117-
def pytest_collect_file(parent, path):
118-
if path.ext == ".yaml" and path.basename.startswith("test"):
119-
return YamlFile.from_parent(fspath=path, parent=parent)
117+
def pytest_collect_file(parent, fspath):
118+
if fspath.suffix == ".yaml" and fspath.name.startswith("test"):
119+
return YamlFile.from_parent(path=fspath, parent=parent)
120120
121121
class YamlFile(pytest.File):
122122
def collect(self):
123-
yield YamlItem.from_parent(name=self.fspath.basename, parent=self)
123+
yield YamlItem.from_parent(name=self.path.name, parent=self)
124124
125125
class YamlItem(pytest.Item):
126126
def runtest(self):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
def pytest_ignore_collect(path):
1+
def pytest_ignore_collect(fspath):
22
return False

testing/example_scripts/fixtures/custom_item/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ def collect(self):
1111
yield CustomItem.from_parent(name="foo", parent=self)
1212

1313

14-
def pytest_collect_file(path, parent):
15-
return CustomFile.from_parent(fspath=path, parent=parent)
14+
def pytest_collect_file(fspath, parent):
15+
return CustomFile.from_parent(path=fspath, parent=parent)

testing/example_scripts/issue88_initial_file_multinodes/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ def collect(self):
66
return [MyItem.from_parent(name="hello", parent=self)]
77

88

9-
def pytest_collect_file(path, parent):
10-
return MyFile.from_parent(fspath=path, parent=parent)
9+
def pytest_collect_file(fspath, parent):
10+
return MyFile.from_parent(path=fspath, parent=parent)
1111

1212

1313
class MyItem(pytest.Item):

0 commit comments

Comments
 (0)