Q:

Patching os.path.isfile with side_effects not working in list comprehension

I'm attempting to excercise the following method in a Python class:
def find_tests(self):
    tests_dir = glob.glob("tests/*")
    if not tests_dir:
        return None

    # Filter out only the files in tests/ then get the test names.
    tests = [os.path.basename(t) for t in tests_dir if os.path.isfile(t)]

With the following test:
@patch('glob.glob')
@patch('os.path.isfile')
def test_conductor_find_tests(self, mock_isfile, mock_glob):
    tests_directory = ['tests/00-test', 'tests/02-juju', 'tests/lib',
                       'tests/01-ubuntu']
    test_names = ['00-test', '01-ubuntu', '02-juju']
    files_exist = [True, True, False, True]
    mock_isfile.side_effects = files_exist
    mock_glob.return_value = tests_directory

    args = Arguments(tests = 'dummy')
    c = juju_test.Conductor(args)
    results = c.find_tests()

    mock_glob.assert_called_with('tests/*')
    self.assertEqual(results, test_names)

mock_isfile gets run (verified with mock_isfile.call_count), however, it does not return False for the third list element, instead it lets all fly through and I end up with this:
======================================================================
FAIL: test_conductor_find_tests (test.test_juju_test.JujuTestPluginTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/marco/Projects/juju-plugins/test/test_juju_test.py", line 51, in test_conductor_find_tests
    self.assertEqual(results, test_names)
AssertionError: Lists differ: ['00-test', '01-ubuntu', '02-j... != ['00-test', '01-ubuntu', '02-j...

First list contains 1 additional elements.
First extra element 3:
lib

- ['00-test', '01-ubuntu', '02-juju', 'lib']
?                                   -------

+ ['00-test', '01-ubuntu', '02-juju']

----------------------------------------------------------------------

What do I need to do in order to properly get os.path.isfile patch to respect these return values?

A:

The attribute is called side_effect, not side_effects. 

