-
Notifications
You must be signed in to change notification settings - Fork 39
filter/skipif combination of cases from multiple parametrize_with_cases decorators #195
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 @eavanvalkenburg for the kind words ! Glad you're finding this lib useful. I understand your problem, but I do not see a proper way to solve it. Maybe @saroad2 will have an API idea here as he is fond of filtering ;) For a quick workaround I would go for the "if" statement combined with Otherwise maybe a more general Other ideas welcome ! @plammens @shaunc if you have brain bandwidth available :) |
yeah, the get_current_case* isn't much easier then just using a if condition block against the actual parameters that were passed in because of the cases, so this will work for now, but would be cool if you guys think of something here, because that would make it much more explicit, to see a skipped in the log instead of a passed for those instances! |
I had this problem too, and I think I was mostly able to overcome it using tags. You can pass a list of tags to both case decorator and parametrize_with_cases. Tags seem mostly for inclusion rather than exclusion, (@smarie - how about boolean tag expression support?) but since you can tag with a list, with a little work you can often come up with a way to exclude. (e.g., "not_encrypted" tag, together with some "neutral" tag in other cases -- e.g. "all_protos" ...?) In fact maybe the "neutral" tags can be avoided if you use @parametrize_with_cases directly? Another technique I use is to select subsets by creating a fixture that combines all the cases, then use @fixture
@parametrize_with_cases("encrypted", prefix="encrypted_", has_tag="not_encrypted")
@parametrize_with_cases("protocol", prefix="proto_")
def ne_cases(encrypted, protocol):
return (encrypted, protocol)
ne_encrypted, ne_protocol = unpack_fixtures("ne_encrypted, ne_protocol", ne_cases) |
If this is the point that bothers you, you can write @shaunc thanks for adding your thoughts here ! The filtering features, with the new helper functions from @saroad2 ( |
Indeed crossing the decorator boundary is the issue! and thanks for the tip about the pytest.skip, didn't know that one, will use that for now, you can close this if you want (or keep it open in case you want to refer to it later as a feature)! |
@smarie -- two cases -- ah, sorry. One could make new cases individual items of cross product in a pair, leaving some out, then gather together and unpack again to get fixtures running over the desired subset. A lot of writing to do manually, but perhaps a helper could automate. |
@eavanvalkenburg I found a way for you to solve this issue: with the new fixture @parametrize_with_cases("a", ...)
@parametrize_with_cases("b", ...)
def test_foo(a, b, current_cases):
if current_cases["a"] is case_a and current_cases["b"] is case_b:
pytest.skip("This combination of cases does not make sense") Note that cases used to parametrize a fixture appear in this dictionary too, but one level deeper (under the fixture name). Let me know if this solves your problem, and I'll close the issue then. |
@eavanvalkenburg I'll close this now, but feel free to reopen if this did not solve your issue ! |
Hi, loving the library! I have a instance where I create a large number of test cases based on a combination of multiple parametrize_with_cases, a simple example here:
in test_package_cases.py:
and in test_package.py
This is a simplified example of what I want to achieve (I have one test that has 5 parametrize_with_cases, with a total of 80 tests coming out of it, which I love!), but let's say I now want to exclude the test for TCP Encrypted, I would have expected either a Filter or using something like pytest.mark.skipif(protocol==TCP and encrypted is not None) to do this, but that doesn't seem to work, and in the filter doc, I seem to read that a filter only applies to a single parametrize call, so you couldn't use both variables there.
The workaround right now is to skip in the code, but I don't really like that approach!
The text was updated successfully, but these errors were encountered: