Python: assert call to a list that contains a variable
Question: This question follows python 2.7.3 syntax. In unittest framework, suppose I
have the following set up:

    
    
    import mock;
    my_mock = mock.Mock();
    my_patch = mock.patch("my_method", my_mock);
    

Now suppose my_method takes on a list argument as input.

How Can I use my_mock.assert_any_call to make sure that a call is made to
my_method such that the input list contains a particular value?


Answer: You can do that by use both
[`mock_calls`](https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.mock_calls)
and call unpacking as documented
[here](https://docs.python.org/3/library/unittest.mock.html#call). Now a for
cycle can be enough to do the work:

    
    
    >>> import mock
    >>> m = mock.Mock()
    >>> m([1,2])
    <Mock name='mock()' id='140596484020816'>
    >>> m([5,6])
    <Mock name='mock()' id='140596484020816'>
    >>> m([8,9])
    <Mock name='mock()' id='140596484020816'>
    >>> for name,args,kwrgs in m.mock_calls:
    ...     if 5 in args[0]:
    ...         print("found")
    ... 
    found
    

