title: How to use unittest.mock to mock arbitrary ConfigParser calls in a unit test
body: <p>I'm trying to start using <a href="http://docs.python.org/3/library/unittest.mock.html" rel="nofollow">unittest.mock</a>'s action/assert pattern instead of <a href="https://code.google.com/p/pymox/wiki/MoxDocumentation" rel="nofollow">mox</a>'s record/replay/verify pattern.  </p>
  
  <pre><code># foo.py
  def op_1(param):
      pass
  
  def op_2(param):
      pass
  
  def do_stuff(param_1, param_2):
      global config
      global log
      try:
          op_1(param_1)
          if config.getboolean('section','option'):
              op_2(param_2)
      except:
           log.error("an error occured")
  </code></pre>
  
  <p>And, here's an example of what my unittest file looks like.</p>
  
  <pre><code># test_foo.py
  class TestFoo(unittest.TestCase):
      def test_do_stuff(self):
          param_1 = None
          param_2 = None
          foo.config = MagicMock()
          foo.config.getboolean('section','option', return_value = True)
          foo.op_1 = MagicMock()
          foo.op_2 = MagicMock()
          do_stuff(param_1, param_2)
          foo.op_1.assert_called_once_with(param_1)
          foo.op_2.assert_called_once_with(param_2)
          foo.config.getboolean.assert_called_once_with('section','option')
  </code></pre>
  
  <p>Does this test to verify the items below/am I using mock right?</p>
  
  <ol>
  <li>do_stuff call returned without error</li>
  <li>op_1 was called with param_1</li>
  <li>op_2 was called with param_2</li>
  <li>config parser object had been used, but the specific calls don't matter</li>
  </ol>