main: avoid Path(Path(...)) calls, they're slow

This commit is contained in:
Ran Benita 2021-10-01 15:19:40 +03:00
parent 7720154ca0
commit c86ceb4d01
1 changed files with 7 additions and 3 deletions

View File

@ -538,14 +538,18 @@ class Session(nodes.FSCollector):
pytest_collectreport = pytest_runtest_logreport
def isinitpath(self, path: Union[str, "os.PathLike[str]"]) -> bool:
return Path(path) in self._initialpaths
# Optimization: Path(Path(...)) is much slower than isinstance.
path_ = path if isinstance(path, Path) else Path(path)
return path_ in self._initialpaths
def gethookproxy(self, fspath: "os.PathLike[str]"):
# Optimization: Path(Path(...)) is much slower than isinstance.
path = fspath if isinstance(fspath, Path) else Path(fspath)
pm = self.config.pluginmanager
# Check if we have the common case of running
# hooks with all conftest.py files.
pm = self.config.pluginmanager
my_conftestmodules = pm._getconftestmodules(
Path(fspath),
path,
self.config.getoption("importmode"),
rootpath=self.config.rootpath,
)