From c86ceb4d01176af5ed1163dfe01bd35633b83c4e Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 1 Oct 2021 15:19:40 +0300 Subject: [PATCH] main: avoid Path(Path(...)) calls, they're slow --- src/_pytest/main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index e068fcb0c..6bfd54c39 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -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, )