I can't get minimock and nosetests to play nice

John J. Lee jjl at pobox.com
Mon Oct 22 08:41:18 EDT 2007


Matthew Wilson <matt at tplus1.com> writes:

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

This has nothing to do with nose.


> 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')

This does not rebind the module global name "Chicken".


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

g() returns None, and prints nothing.

[...]
> 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

... because g() returns None, and prints nothing.

[...]
> Any ideas?

Read the Python tutorial, write some Python code and some doctests
without using minimock.  Google about Python scoping rules.  Read the
doctest docs about the global namespace seen by doctest-ed code:

http://docs.python.org/lib/doctest-execution-context.html


John



More information about the Python-list mailing list