By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,723 Members | 828 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,723 IT Pros & Developers. It's quick & easy.

I can't get minimock and nosetests to play nice

P: n/a


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.getv alue()))
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
Oct 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Matthew Wilson <ma**@tplus1.comwrites:
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-e...n-context.html
John
Oct 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.