-
Notifications
You must be signed in to change notification settings - Fork 39
Question: How to conditionally skip a generated test case #211
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
Thanks for this question @wonboyn We'll need a complete reproducible example to discuss. Let's use this one: from pytest_cases import parametrize, parametrize_with_cases
class MyClassName:
@parametrize(name=("joe", "bob", "alice"))
def case_widget(self, name):
return name
def case_foo(self):
return "foo"
@parametrize_with_cases('val', cases=MyClassName)
def test_function(val):
print(val) This generates 4 test nodes:
The first 3 test nodes use the case Your question is about selecting both Filtering cases: KOUnfortunately, filtering cases (using filters, tags, globs as described in here) applies solely on the cases directly collected by Inspecting
|
Thanks for getting back to me. In the short term I've gone with the option of evaluating each case in the test function & skipping if not appropriate. I guess the better longer term option is a custom function to filter the results currently being parametrized. |
Thanks @wonboyn for the feedback! |
Hi @wonboyn , just for information: #214 has now been fixed in 3.6.0 so you can now solve your problem easily with the @parametrize_with_cases('val', cases=MyClassName)
def test_function(val, current_cases):
print(val)
# get the current case and its parameters
val_id, val_func, val_params = current_cases['val']
# skip if the case is widget and its param is "joe"
if val_func is MyClassName.case_widget and val_params["name"] == "joe":
pytest.skip("joe is skipped !")
... Let me know if this works ok for you |
Hi there,
I have a test case function that's using the @parametrize decorator:
`
@parametrize(name=(HelperUtil.get_all_widgets()))
def case_widget(self, name):
return name
`
Then on the test function I have @parametrize_with_cases:
`
@parametrize_with_cases('val', cases=MyClassName)
def test_function(val):
`
This is working perfectly & processing the dozen odd values that get returned from @parametrize.
However, I'd like the test function that uses this to skip certain "name" values (eg skip if name in ['fred', 'harry', 'mick']
Based on your doco, I think the @parametrize_with_cases(filter=) option using regex can probably do this.
Can this be achieved with filters & if so what's the format of id's that get returned from @parametrize?
Thanks in advance.
Tim
The text was updated successfully, but these errors were encountered: