TransWikia.com

Know how function with external methods was called without editing it in Python

Stack Overflow Asked by thlik on February 17, 2021

I couldn’t find an answer so I ask:

Let’s say I have a file with these functions:

def method_1(param1, param2):
    send_email(param1)
    print('method_1 is done')               
    
def method_2(param1, param2):
    new_param = external_method(param1)
    method_1(new_param['key'], param2)
    print('method_2 is done')

They are part of some MVC framework, and I’m trying to write a test, so changing the functions is not an option. The test would be to check whether the sent email is correct.

external_method() depends on an external API, so I don’t know what it will return, meaning that whatever I write to mock it, it will be inaccurate to a real-life setting.

All I know about external_method‘s result is that it should be in the form of a dict and contain a key called 'key'

Without editing the code above, is there a way to know if send_email inside method_1 was called with the right param1? Meaning that the email contains what I expect it to contain based on the origin of param1.

I know that I could use a runtime debugger but I was wondering if there are other solutions.

One Answer

I figured this out:

Without editing the code above, is there a way to know if send_email inside method_1 was called with the right param1?

No. This requires us being able to check the email methods; so it's a different scope.

Answered by thlik on February 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP