How can I test how many times a function is called?

Viewed 36

I have used the following suggestion to set up my code: https://www.faqcode4u.com/faq/602190/checking-whether-function-has-been-called-multiple-times-with-different-parameters

I would like to test how many times the function write_standalone_end_of_event is called.

#exchanges.impl.bats.mcformat.py
def delete_data(...): 
    exg = exchanges.impl.bate.parser.Exchange
    securities = [one_item]
    
    for security in securities: 
        exg.write_standalone_end_of_event


#unit_test_package
with patch('exchanges.impl.bate.parser.Exchange.write_standalone_end_of_event') as function:
    bats.protocol.sec_id_in_batch = {1: 'dummy1'}
    bats.protocol.transaction_end(exg, fields, values, msgtype, sequence)
    assert function.gacs.call_count == 1

When I run the above, i get an asserTion error that 0 != 1.

I can't seem to figure out why the function is not picking up the one call to it, even though when I debug it, it does seem to call write_standalone_end_of_event one time.

0 Answers
Related