Skip to content

Commit 3f3847b

Browse files
author
gdhameeja
committed
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. In such cases we check if `TypeError` is raised and raise a `UsageError`
1 parent bd7e332 commit 3f3847b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/_pytest/mark/legacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@ def matchkeyword(colitem, keywordexpr):
106106
)
107107
try:
108108
return eval(keywordexpr, {}, mapping)
109-
except SyntaxError:
109+
except (SyntaxError, TypeError):
110110
raise UsageError("Wrong expression passed to '-k': {}".format(keywordexpr))

0 commit comments

Comments
 (0)