-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2953 show a simple and easy error when keyword expressions trigger a syntax error #3121
#2953 show a simple and easy error when keyword expressions trigger a syntax error #3121
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! You might want to use the keyword module instead, though 😉
…rte/pytest into 2953-keyword-expressions-error
fixed =) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
Just please check if raising UsageError
provides a better message.
_pytest/mark.py
Outdated
return eval(keywordexpr, {}, mapping) | ||
for kwd in keywordexpr.split(): | ||
if keyword.iskeyword(kwd) and kwd not in python_keywords_allowed_list: | ||
raise AttributeError("Python keyword '{}' not accepted in expressions passed to '-k'".format(kwd)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think raising UsageError
might be more appropriate and provide a better user experience because it won't show up as an internal error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
…rte/pytest into 2953-keyword-expressions-error
@feuillemorte I tested this locally and is looking good, thanks! I just pushed a change that makes the error message appear in red to make it more visible. 😉 After this passes I think we can merge it. 👍 |
Let's wait for @The-Compiler to take a second look before we merge it. 👍 |
LGTM! Travis is currently recovering from an outage, so that'll probably take a bit. |
@The-Compiler thanks for the info. Should we restart the Travis job? Not sure from the outage report if that's something we should attempt or not. |
Hmm, dunno. I'd say let's just wait some more hours since the job apparently wasn't cancelled. |
@The-Compiler the problem was solved. could you restart it, please? |
I don't think it'll help (as the build wasn't cancelled), but I did. |
Looking good now - thanks! |
If we use expressions in -k option we get an error if this expression wrong of has python keywords:
AttributeError: Python keyword 'import' not accepted in expressions passed to '-k'
AttributeError: Wrong expression passed to '-k': foo or