Store mark's evalcache in config's store instead of attribute
Part of moving away from ad-hoc attributes to using the config's store.
This commit is contained in:
parent
b1d7a187f2
commit
f011bc642c
|
@ -2,21 +2,28 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
from typing import Any
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
from ..outcomes import fail
|
from ..outcomes import fail
|
||||||
from ..outcomes import TEST_OUTCOME
|
from ..outcomes import TEST_OUTCOME
|
||||||
|
from _pytest.config import Config
|
||||||
|
from _pytest.store import StoreKey
|
||||||
|
|
||||||
|
|
||||||
def cached_eval(config, expr, d):
|
evalcache_key = StoreKey[Dict[str, Any]]()
|
||||||
if not hasattr(config, "_evalcache"):
|
|
||||||
config._evalcache = {}
|
|
||||||
|
def cached_eval(config: Config, expr: str, d: Dict[str, object]) -> Any:
|
||||||
|
default = {} # type: Dict[str, object]
|
||||||
|
evalcache = config._store.setdefault(evalcache_key, default)
|
||||||
try:
|
try:
|
||||||
return config._evalcache[expr]
|
return evalcache[expr]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
|
|
||||||
exprcode = _pytest._code.compile(expr, mode="eval")
|
exprcode = _pytest._code.compile(expr, mode="eval")
|
||||||
config._evalcache[expr] = x = eval(exprcode, d)
|
evalcache[expr] = x = eval(exprcode, d)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue