Hello,
I need help to mock some Class/variable in python test. Here is the scenario:
I want to mock app_client_instance and AppClient except FeatEng but it is not working. I don't know how to pass mocks to the FeatEng as no constructor on static class.
Have you a way to help?
Regards
I need help to mock some Class/variable in python test. Here is the scenario:
app_client.py class AppClient: def __init__(self): self.val = None def get_value(self, feature_eng): .................................................... app_client_instance.py from app_client import AppClient app_client_instance = AppClient() .................................................... from app_client_instance import app_client_instance class FeatEng: @staticmethod def is_activ(feature_eng): client = app_client_instance value = client.get_value(feature_eng) return "true" == value .................................................... unit test with magicMock def test_mockmag(self): client = MagicMock(spec=AppClient, name=AppClient) client.get_value.return_value = "false" instance = MagicMock(spec=app_client_instance) instance.app_client_instance.return_value = client result = FeatEng.is_activ("MIG_ENG")I have a static class FeatEng importing a variable app_client_instance, this last creates an object of the AppClient class.
I want to mock app_client_instance and AppClient except FeatEng but it is not working. I don't know how to pass mocks to the FeatEng as no constructor on static class.
Have you a way to help?
Regards
Larz60+ write Oct-10-2021, 08:06 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts,
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts,