You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am looking into your interesting plugin and like the separation of concerns cases and tests.
My question is, if there is already a mechanism to override default cases based on attribute like a fixture for example:
Hi @MischaZihler , thanks for the interesting question !
If I understand correctly, your question relates to the general scenario of reusing a collection of cases (e.g. class CasesA across various tests (e.g. test_a and test_b), and you are interested in the possibility of keeping some flexibility, for example having one of the cases in CasesA overridden when the collection is used in test_b.
Such static flexibility could I guess, be done with subclasses (CasesAOverridden would inherit from CasesA and override only some of the cases) but currently this is not working:
File "C:\_dev\python_ws\_Libs_OpenSource\python-pytest-cases\src\pytest_cases\case_parametrizer_new.py", line 914, in _extract_cases_from_module_or_class
m_def_in_cls = cls.__dict__[m_name]
KeyError: 'case_normal_inherited'
So today, inheritance of cases between cases classes is currently not supported. I should make that more explicit in the error message.
A simple workaround for now is to list all cases that are inherited, explicitly:
classACasesOverridden(ACases):
@staticmethoddefcase_static_overridden():
return3defcase_normal_overridden(self):
return3# For staticmethod and classmethod, you need to ref the __dict__case_static_inherited=ACases.__dict__['case_static_inherited']
# For standard methods this is more straightforwardcase_normal_inherited=ACases.case_normal_inherited
So for all inherited methods, either you redefine them or you explicitly list them.
This seems to work fine from what I've tested.
Would this be what you're looking for or are you chasing a more complex use case ? Note that dynamically switching between parameters (for example based on a fixture's code content) is not possible in pytest, because pytest works with a static plan: (1) it collects all parameters and fixture definitions without executing anything, and (2) it executes the plan
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I am looking into your interesting plugin and like the separation of concerns cases and tests.
My question is, if there is already a mechanism to override default cases based on attribute like a fixture for example:
Or is this generally solved with a different logic?
Regards
Mischa
The text was updated successfully, but these errors were encountered: