Cache splitnode results to improve tests collection time (#5681)
Cache splitnode results to improve tests collection time
This commit is contained in:
commit
dc6e7b9fcf
|
@ -0,0 +1 @@
|
||||||
|
Cache node splitting function which can improve collection performance in very large test suites.
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
import py
|
import py
|
||||||
|
|
||||||
|
@ -13,6 +14,7 @@ SEP = "/"
|
||||||
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
|
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=None)
|
||||||
def _splitnode(nodeid):
|
def _splitnode(nodeid):
|
||||||
"""Split a nodeid into constituent 'parts'.
|
"""Split a nodeid into constituent 'parts'.
|
||||||
|
|
||||||
|
@ -30,11 +32,12 @@ def _splitnode(nodeid):
|
||||||
"""
|
"""
|
||||||
if nodeid == "":
|
if nodeid == "":
|
||||||
# If there is no root node at all, return an empty list so the caller's logic can remain sane
|
# 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)
|
parts = nodeid.split(SEP)
|
||||||
# Replace single last element 'test_foo.py::Bar' with multiple elements 'test_foo.py', 'Bar'
|
# Replace single last element 'test_foo.py::Bar' with multiple elements 'test_foo.py', 'Bar'
|
||||||
parts[-1:] = parts[-1].split("::")
|
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):
|
def ischildnode(baseid, nodeid):
|
||||||
|
|
Loading…
Reference in New Issue