0

Here is my function that I want to write a unit test for:

def check_files_content(files_spec):
    for item in files_specs:
        do_something
        ....

Here is the unit test:

def test_check_files_content(): 
    check_files_content(MagicMock())??
    .... 

I don't know how to set up files_specs using MagicMock() so that I can set each item in files_specs to whatever I want, as we loop over the list.

Any ideas how this can be achieved?

ifrj
  • 91
  • 7
  • 1
    You don't need a mock here, the value you wanted to control in your test is the arg to the function you are calling in the test. i.e. you can just pass the test value you want to in your test function. – Anentropic Jul 20 '23 at 12:16
  • You're completely right.... I realised after trying a few things. Thanks for responding though. – ifrj Jul 20 '23 at 12:17
  • You might put some mock values in the test list if e.g. you wanted to check if they were called or something. So in your test func you could `mock1 = MagicMock(); test_list = [mock1]; check_files_content(test_list)` and then later inspect properties of `mock1` – Anentropic Jul 20 '23 at 12:20

0 Answers0