jeudi 28 avril 2016

python mock on method returning mock rather than return_value?

Consider the following (really simple) unit test file:

import unittest
from mock import Mock

class TestMuPE(unittest.TestCase):

  def test_01(self):
    mock_buffer = Mock()
    mock_buffer.frame_count.return_value(42)
    self.assertEquals(mock_buffer.frame_count(), 42)

    # => AssertionError: <Mock name='mock.frame_count()' id='4413645520'> != 42

I would expect mock_buffer.frame_count() to evaluate to 42, but instead it's returning a mock object. What am I missing?

P.S.: I'm running Python 2.7.11 with the mock-2.0.0 backport loaded.

Aucun commentaire:

Enregistrer un commentaire