Cache split nodes results to reduce long tests collection time on large test suites

This commit is contained in:
Alexey Zankevich 2019-08-01 20:46:27 -04:00
parent cb15e7c700
commit b43ebb7d65
2 changed files with 6 additions and 2 deletions

View File

@ -0,0 +1 @@
Cache node splitting function which can improve collection performance in very large test suites.

View File

@ -1,5 +1,6 @@
import os
import warnings
from functools import lru_cache
import py
@ -13,6 +14,7 @@ SEP = "/"
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
@lru_cache(maxsize=None)
def _splitnode(nodeid):
"""Split a nodeid into constituent 'parts'.
@ -30,11 +32,12 @@ def _splitnode(nodeid):
"""
if nodeid == "":
# If there is no root node at all, return an empty list so the caller's logic can remain sane
return []
return ()
parts = nodeid.split(SEP)
# Replace single last element 'test_foo.py::Bar' with multiple elements 'test_foo.py', 'Bar'
parts[-1:] = parts[-1].split("::")
return parts
# Convert parts into a tuple to avoid possible errors with caching of a mutable type
return tuple(parts)
def ischildnode(baseid, nodeid):