473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

I can't get minimock and nosetests to play nice



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
1 1455
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: Brad Kunkel | last post by:
<deanmartin@wk.shawcable.net> wrote in message news:5IOjc.278413$Pk3.274338@pd7tw1no... > Short avi clip of me fucking a goat. Enjoy > > ...
1
by: Empire City | last post by:
I have to give a 3 hour C#.NET speech/presentation to a non-technical and/or semi-non-technical audience. Can anyone point me to some resources to put this together? Thank you.
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
13
by: anil.rita | last post by:
When the user chooses an AV file to play, based upon the type of file, I want to use the default installed media player to play it. I am wondering if this is a good way - any alternatives,...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
4
by: newbie | last post by:
Say I have the following class: class MyAbs { virtual ~MyAbs() {} virtual void foo() = 0; virtual void bar() {cout << "abs::bar"; } } class MyDer1: public MyAbs { MyDer1() {counter = 0; }
1
by: Smithers | last post by:
I'm writing a Console app that will run on a periodical basis on busy Web servers. The console app is responsible for backing up files uploaded to the Web server (copying the files out to a backup...
5
by: | last post by:
Hello, I am wrtting a program that does some sound effects... the files are stored in a subfolder in the application folder... and I check the existence of the files before calling the method to...
4
by: Mr.SpOOn | last post by:
Hi, I'm trying the nose testing package. I've just started reading the tutorial and I had a problem with the first simple example. This is the test: def test_b(): assert 'b' == 'b' In the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.