I am unit testing a single line of code within an if statement where I append an item onto a list if a variable has a specific value.
foo = []
if bar == 'a':
foo.append(bar)
I would like to assert that such an append has been called. I have patched methods from a variety of sources before, but not methods belonging to basic Python data types. What class would I specify as the path for the mock.patch decorator?
@mock.patch('append')
def test_appends_bar_to_foo(mock_append):
assert mock_append.called
With the above code, I get TypeError: Need a valid target to patch. You supplied: 'append'