-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
-k mishandles numbers #7112
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
Comments
IMO this is a bug. This happens before the If you are interested on working on it, IMO it would be good to move away from |
@bluetech indeed! Thanks for the pointer, it seems to be really the same problem as the other issue. |
Previously, the expressions given to the `-m` and `-k` options were evaluated with `eval`. This causes a few issues: - Python keywords cannot be used. - Constants like numbers, None, True, False are not handled correctly. - Various syntax like numeric operators and `X if Y else Z` is supported unintentionally. - `eval()` is somewhat dangerous for arbitrary input. - Can fail in many ways so requires `except Exception`. The format we want to support is quite simple, so change to a custom parser. This fixes the issues above, and gives us full control of the format, so can be documented comprehensively and even be extended in the future if we wish. Fixes pytest-dev#1141. Fixes pytest-dev#3573. Fixes pytest-dev#5881. Fixes pytest-dev#6822. Fixes pytest-dev#7112.
Previously, the expressions given to the `-m` and `-k` options were evaluated with `eval`. This causes a few issues: - Python keywords cannot be used. - Constants like numbers, None, True, False are not handled correctly. - Various syntax like numeric operators and `X if Y else Z` is supported unintentionally. - `eval()` is somewhat dangerous for arbitrary input. - Can fail in many ways so requires `except Exception`. The format we want to support is quite simple, so change to a custom parser. This fixes the issues above, and gives us full control of the format, so can be documented comprehensively and even be extended in the future if we wish. Fixes pytest-dev#1141. Fixes pytest-dev#3573. Fixes pytest-dev#5881. Fixes pytest-dev#6822. Fixes pytest-dev#7112.
Using
pytest 5.4.1
.It seems that pytest cannot handle keyword selection with numbers, like
-k "1 or 2"
.Considering the following tests:
Selecting with
-k 2
works:But selecting with
-k "1 or 2"
doesn't, as I get all tests:If I make it a string though, using
-k "_1 or _2"
, then it works again:I see there are some notes about selecting based on keywords here but it was not clear if it applied to this case:
http://doc.pytest.org/en/latest/example/markers.html#using-k-expr-to-select-tests-based-on-their-name
So, is this a bug? Thanks!
The text was updated successfully, but these errors were encountered: