I'm trying to test a function in which one call results in multiple files being written:
def pull_files(output_files=[]):
for output_file in output_files:
content = get_content_from_server(output_file)
with open('/output/' + output_file, "wb") as code:
code.write(content)
I want my test to check that each call was made to open as expected, and that the content was written:
def test_case(self):
pull_files("file1.txt", "file2.txt")
# Assert open("file1.txt", "wb") was called
# Assert "file 1 content" was written to "file1.txt"
# Assert open("file2.txt", "wb") was called
# Assert "file 2 content" was written to "file2.txt"
I've seen an example of handling two files here: Python mock builtin 'open' in a class using two different files
But I can't wrap my head around how to track what is actually written to them.