-
-
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
filter expressions unreliable when parametrizing test #3243
Comments
i suspect the keyword expression is matching the |
Hah! Good catch! That means I constructed my minimal example poorly, since that's not the case in the real-world issue I'm having. This one demonstrates the issue I'm having better: import pytest
@pytest.mark.parametrize(
'bar', [
'abc-1',
'def-1',
'ghi-1',
'jkl-1'
],
)
def test_foo(bar):
assert(True)
Take out the dashes from the parameters and filters and it behaves as expected:
I've found elsewhere in this issue tracker that filters are treated as Python expressions. That probably means that the dash is interpreted as a minus sign instead of a literal character. Unfortunately I really need those dashes in my parameters and I need to be able to filter on them. |
Meanwhile I've found an ugly workaround that allows me to apply the filters I want. Replacing the dashes in with underscores in the ids and then also using underscores in the filter works well, without actually changing the original parameter that is fed into my test. import pytest
@pytest.mark.parametrize(
'bar', [
'abc-1',
'def-1',
'ghi-1',
'jkl-1'
],
ids=lambda x: x.replace('-', '_')
)
def test_foo(bar):
assert("-" in bar and "_" not in bar)
|
@rasschaert thans for showing your solution , its a fine hack to work around that current shortcoming of pytest we hope to eventually enable better selection fo marks, but thats still far off |
Closing as this has not seen activity in awhile. |
@nicoddemus this one hasnt been fixed as far as i can tell |
Thanks @RonnyPfannschmidt for catching my slip up. |
Looking again at this, I'm not sure if this is solvable: If we want to change how |
personally i wonder if we should just introduce a new option to express filters and then at a later point deprecate -m and -k |
Filter expressions (-k) become very unreliable when you try to match the parameters in parameterized fixtures. The filters seem to match things they shouldn't.
Minimal example:
Filtering for 'z' matches everything (which is, I'm pretty sure, incorrect behaviour).
Different filters do work as expected.
My system is Arch Linux, the relevant software versions are in my pytest output.
pip list:
Being able to select/deselect certain tests based on the parameter names is quite important to my use case. Please let me know if I can further help narrow down the issue.
The text was updated successfully, but these errors were encountered: