473,289 Members | 1,756 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,289 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 1452
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.