Related post on Mocking global variables
outgoing.py
table_data = []
def outgoing_data():
record = *do some stuff*
table_data.append(record)
In a unit test I want to verify that table_data
is updated. I tried setting it up as shown in the related post but that seems more aimed at using that global variable inside the function by setting its value in the patch. I have been successful in patching the global variable with data to be used in other methods using: @patch('outgoing.outgoing_data.table_data', [{'action_hist_id': 1, 'page_num': 1, 'row_num': 1}])
as a decorator.
I tried @patch('outgoing.outgoing_data.table_data', [])
but that didn't work as expected. I was anticipating that a mock would be generated by patch, which it probably was, but I couldn't see it in the debug window to find out if it was called etc.
Let me know if the question isn't clear or needs more info. Thanks in advance.