title: How to mock a list in Python?
body: <p>For example, I have some code which tries to access a list:</p>
  
  <pre><code>def some_code():
      script_dir = os.path.dirname(sys.argv[0])
  </code></pre>
  
  <p>I need to mock <code>sys.argv[0]</code>. So I add <code>@patch.object</code> to my test:</p>
  
  <pre><code>import os
  import sys
  
  THIS_DIR = os.path.dirname(os.path.abspath(__file__))
  @mock.patch.object(sys, 'argv', mock.Mock(return_value=[THIS_DIR]))
  def test_mytest():
      some_code()
  </code></pre>
  
  <p>But this doesn't work. Pytest raises error:</p>
  
  <pre><code>&gt;     script_dir = os.path.dirname(sys.argv[0])
  E     TypeError: 'Mock' object does not support indexing
  </code></pre>
  
  <p>What am I doing wrong?</p>