MarkBerlin78 / pymox

Automatically exported from code.google.com/p/pymox
Apache License 2.0
0 stars 0 forks source link

Method call failures involving MockAnything are unprintable #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When trying to use MockAnything in a recorded method call, failures will be
unprintable because MockAnything will record the __repr__ call and raise an
exception.

Using this test code:

mock = mox.Mox ()
mock_qs = mock.CreateMockAnything ()
mock_qs.all ().AndReturn (mock_qs)
mock.ReplayAll ()
mock.VerifyAll ()

Causes this (rather unhelpful) failure:

Traceback (most recent call last):
  File "tests/test_gallery.py", line 47, in test_already_contains
    mock.VerifyAll ()
  File "/usr/lib/python2.5/site-packages/mox-0.5.0-py2.5.egg/mox.py", line
197, in VerifyAll
    mock_obj._Verify()
  File "/usr/lib/python2.5/site-packages/mox-0.5.0-py2.5.egg/mox.py", line
344, in _Verify
    raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: <unprintable ExpectedMethodCallsError object>

Original issue reported on code.google.com by jmilli...@gmail.com on 4 Oct 2008 at 5:06

GoogleCodeExporter commented 9 years ago
Is there a workaround while this is being fixed to know what really failed?

Original comment by praveen....@gmail.com on 12 Nov 2008 at 12:23

GoogleCodeExporter commented 9 years ago
This is a rather naive fix (it will mess up actual attempts to mock __str__ and
__repr__) but it's been helpful for me in terms of debugging.  In the 
MockAnything
class definition (mox.py ln 265) add the following:

def __str__(self):
  return "<MockAnything instance>"

def __repr__(self):
  return self.__str__()

Original comment by agora...@gmail.com on 18 Feb 2009 at 3:34

GoogleCodeExporter commented 9 years ago
Attached is a patch against r28 with agoartim's change and a test that 
exercises it.

Original comment by therobot...@gmail.com on 29 Apr 2009 at 6:07

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed in revision 29.  Thanks for the patch! :)

Original comment by smidd...@gmail.com on 5 May 2009 at 10:55