Skip to content

Commit

Permalink
main: avoid Path(Path(...)) calls, they're slow (pytest-dev#9147)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech committed Oct 1, 2021
2 parents 5fc3e35 + c86ceb4 commit 8af5587
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,18 @@ def pytest_runtest_logreport(
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,
)
Expand Down

0 comments on commit 8af5587

Please sign in to comment.