[Pytest-commit] commit/pytest: RonnyPfannschmidt: move evaluation and caching of mark expressions to own function
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Apr 13 21:00:00 CEST 2015
1 new commit in pytest:
https://bitbucket.org/pytest-dev/pytest/commits/551a54d002fd/
Changeset: 551a54d002fd
Branch: markexpr-parser
User: RonnyPfannschmidt
Date: 2015-04-13 17:37:34+00:00
Summary: move evaluation and caching of mark expressions to own function
Affected #: 1 file
diff -r bf6f8a626afb870b19a91ff3993203e264fc2e9c -r 551a54d002fda8db9a947063ce37c14ed5edcea0 _pytest/mark.py
--- a/_pytest/mark.py
+++ b/_pytest/mark.py
@@ -113,9 +113,15 @@
return False
+def _match_expr(expr, globals_, __cache={}):
+ if expr not in __cache:
+ __cache[expr] = compile(expr, expr, 'eval')
+ return eval(__cache[expr], {}, globals_)
+
+
def matchmark(colitem, markexpr):
"""Tries to match on any marker names, attached to the given colitem."""
- return eval(markexpr, {}, MarkMapping(colitem.keywords))
+ return _match_expr(markexpr, MarkMapping(colitem.keywords))
def matchkeyword(colitem, keywordexpr):
@@ -150,7 +156,7 @@
return mapping[keywordexpr]
elif keywordexpr.startswith("not ") and " " not in keywordexpr[4:]:
return not mapping[keywordexpr[4:]]
- return eval(keywordexpr, {}, mapping)
+ return _match_expr(keywordexpr, mapping)
def pytest_configure(config):
Repository URL: https://bitbucket.org/pytest-dev/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list