From 599bf075dbf1c1afb1a59b521dca52155c157488 Mon Sep 17 00:00:00 2001 From: gdhameeja Date: Tue, 3 Mar 2020 12:45:32 +0530 Subject: [PATCH] Check invalid operations for -k `KeywordMapping` returns a bool on lookup which when passed to eval fail on certain operations such as index access and attribute access. We catch all exceptions and raise a `UsageError`. --- src/_pytest/mark/legacy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/mark/legacy.py b/src/_pytest/mark/legacy.py index 766b8f9bd..bf8004c1d 100644 --- a/src/_pytest/mark/legacy.py +++ b/src/_pytest/mark/legacy.py @@ -106,5 +106,5 @@ def matchkeyword(colitem, keywordexpr): ) try: return eval(keywordexpr, {}, mapping) - except SyntaxError: + except Exception: raise UsageError("Wrong expression passed to '-k': {}".format(keywordexpr))