From f011bc642c2c42774b0d0893325649075d700f57 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 5 Mar 2020 23:25:04 +0200 Subject: [PATCH] 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. --- src/_pytest/mark/evaluate.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/_pytest/mark/evaluate.py b/src/_pytest/mark/evaluate.py index 53822e98f..772baf31b 100644 --- a/src/_pytest/mark/evaluate.py +++ b/src/_pytest/mark/evaluate.py @@ -2,21 +2,28 @@ import os import platform import sys import traceback +from typing import Any +from typing import Dict from ..outcomes import fail from ..outcomes import TEST_OUTCOME +from _pytest.config import Config +from _pytest.store import StoreKey -def cached_eval(config, expr, d): - if not hasattr(config, "_evalcache"): - config._evalcache = {} +evalcache_key = StoreKey[Dict[str, Any]]() + + +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: - return config._evalcache[expr] + return evalcache[expr] except KeyError: import _pytest._code exprcode = _pytest._code.compile(expr, mode="eval") - config._evalcache[expr] = x = eval(exprcode, d) + evalcache[expr] = x = eval(exprcode, d) return x