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
[Question] Pre-filter cases #258
Comments
Hi @eddiebergman , thanks for this suggestion ! I guess that Maybe we could transform it so that it accepts a module instead ? Otherwise for now you can just pass a fake function from pytest_cases import get_all_cases
def dummy:
pass
my_cases = get_all_cases(dummy, ....) # use your glob and filter here
@parametrize_with_cases("a", cases=my_cases)
def test_foo(a):
... Let me know if this works for you. |
Ahh I never thought about the dummy function approach, I thought it might do some introspection into the arguments of the function. Does this introspection occur? An ideal interface as far as I could imagine doesn't rely on an actual function being defined? I don't see the reason for the function needing to be passed other than to allow for the argument In this case, perhaps # Wherever it is defined
def get_all_cases(f: Optional[Function] = None, cases=..., ...other args)
if cases in [".", AUTO] and f is None:
raise ValueError(...)
... continue as normal and handle logic accordingly
# Some test_file.py
cases = [SomeModule, case_1, case_2, ClassOfCases]
my_cases = get_all_cases(cases=cases, filter=...)
@parametrize_with_cases("x", cases=my_cases)
def test_something(x):
... Perhaps a simpler implementation is just a seperate function |
Yes I think that it was to grab the module, so that relative module names (not only "." but ".xyz", either alone or in an iterable) and AUTO mode is supported. It would indeed be preferable to improve |
Closed in #260 |
Hi @smarie,
I was looking through the documentation and couldn't find any way to pre-filter cases into some kind of iterable that can then be passed to
parametrize_with_cases("x", cases=...)
. My use case is generally to have cases in acases.py
file that is shared throughout the test module.This is useful for testing hierarchies where
A
andB
inherit fromBase
so much of their setup is the same and makes sense to be done in the same filecases.py
, instead of splitting theme out intocases_A.py
andcases_B.py
.Is there some way to do the following:
I'm aware I could just use a filter on each test but there are other tags and the filters tend to get repetitive and I am prone to forgetting them. I could also use a
partial
but this kind of obscures things and doesn't allow additional filtering, i.e.has_tag=["A", "banana"]
.Suggestions on how to about this or how this could be implemented would be greatly appreciated :)
Best,
Eddie
The text was updated successfully, but these errors were encountered: