I can't get minimock and nosetests to play nice

Matthew Wilson matt at tplus1.com
Thu Oct 18 23:10:40 EDT 2007



I'm curious if anyone has ever tried using nosetests along with
minimock.

I'm trying to get the two to play nice and not making progress.  I
also wonder if I'm using minimock incorrectly.

Here's the code I want to test, saved in a file dtfun.py.

    class Chicken(object):
       "I am a chicken."
       def x(self): return 1
       def z(self): return 1

    def g():

       """
       Verify that we call method x on an instance of the Chicken class.

       # First set up the mockery.
       >>> from minimock import Mock
       >>> Chicken = Mock('Chicken')
       >>> Chicken.mock_returns = Mock('instance_of_chicken')

       Now this stuff is the real test.
       >>> g()
       Called Chicken()
       Called instance_of_chicken.x()
       """

       # This is what the function does.
       c = Chicken()
       c.x()

    if __name__ == "__main__":

       # First set up the mockery.
       from minimock import Mock
       Chicken = Mock('Chicken')
       Chicken.mock_returns = Mock('instance_of_chicken')

       # Now run the tests.
       import doctest
       doctest.testmod()

Here's the results when I run the code using doctest.testmod (which
passes) and nosetests --with-doctest (KABOOM):

$ python dtfun.py # Nothing is a good thing here.

$ nosetests --with-doctest dtfun.py
F
======================================================================
FAIL: Doctest: dtfun.g
----------------------------------------------------------------------
Traceback (most recent call last):
 File "doctest.py", line 2112, in runTest
   raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for dtfun.g
 File "/home/matt/svn-checkouts/scratch/python/dtfun/dtfun.py", line 13,
in g

----------------------------------------------------------------------
File "/home/matt/svn-checkouts/scratch/python/dtfun/dtfun.py", line
22, in dtfun.g
Failed example:
   g()
Expected:
   Called Chicken()
   Called instance_of_chicken.x()
Got nothing


----------------------------------------------------------------------
Ran 1 test in 0.015s

FAILED (failures=1)

It seems like nose isn't building the mock objects.

Any ideas?

Matt



More information about the Python-list mailing list