diff options
author | Ran Benita <ran@unusedvar.com> | 2020-07-05 23:11:47 +0300 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2020-07-25 00:47:29 +0300 |
commit | 3633b691d88fbe9bf76137d1af25a0893ebefa84 (patch) | |
tree | b013e29e54bd549c85c0507f1f3c3291c2bfbeed /src/_pytest/main.py | |
parent | c15bb5d3de084a10ade0a99e2f6ec1226aa9356a (diff) | |
download | pytest-3633b691d88fbe9bf76137d1af25a0893ebefa84.tar.gz |
pathlib: make visit() independent of py.path.local, use os.scandir
`os.scandir()`, introduced in Python 3.5, is much faster than
`os.listdir()`. See https://www.python.org/dev/peps/pep-0471/.
It also has a `DirEntry` which can be used to further reduce syscalls in
some cases.
Diffstat (limited to 'src/_pytest/main.py')
-rw-r--r-- | src/_pytest/main.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 7f81c341d..969988305 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -618,11 +618,13 @@ class Session(nodes.FSCollector): assert not names, "invalid arg {!r}".format((argpath, names)) seen_dirs = set() # type: Set[py.path.local] - for path in visit(argpath, self._recurse): - if not path.check(file=1): + for direntry in visit(str(argpath), self._recurse): + if not direntry.is_file(): continue + path = py.path.local(direntry.path) dirpath = path.dirpath() + if dirpath not in seen_dirs: # Collect packages first. seen_dirs.add(dirpath) |