[ python-Feature Requests-708125 ] Requesting Mock Object support for unittest.TestCase

SourceForge.net noreply at sourceforge.net
Thu Jan 22 10:19:17 EST 2004


Feature Requests item #708125, was opened at 2003-03-22 15:05
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=708125&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
>Priority: 3
Submitted By: Matthew Russell (mattruss)
Assigned to: Steve Purcell (purcell)
Summary: Requesting Mock Object support for unittest.TestCase

Initial Comment:
I previously submitted a patch (sf id 706590),
since I was following www.python.com's notes on how 
to contribute - since using sf more i think i should of 
added it to this RFE. Since posting the orignal patch I 
have updated the code based upon sugestions from 
python-dev and others.

please view my origanal patch here:
https://sourceforge.net/tracker/index.php?
func=detail&aid=706590&group_id=5470&atid=305470

This patch adds one method - createMockInstance
(classDef, overrides, *initArgs, **initKwds)
to unittest.TestCase, and two classes MockFactory and 
MockMethod.

Since both these classes should never really be used 
outside the scope of a unittest, I thought it best to add 
them to the unittest module (allthough it is getting rather 
big - should be split into a package?)




----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-01-01 02:01

Message:
Logged In: YES 
user_id=80475

Steve, do you can to pronounce on this one?

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-07-19 19:16

Message:
Logged In: YES 
user_id=80475

Matthew, thanks for the patch.  It gets a little better with 
each update (though it is still in dire need of a spell-check).

The cost/benefit of adding this to the unittest module is not 
clear.  Perhaps, it would be worthwhile to present it on the 
newsgroup to tease out the idea, build a fan club for it, or 
come up with a simpler API.

My biggest issue with the unittest module is that it is already 
too extensive.  One has to read a small book on the subject 
to get started.  The number of doc pages, classes, and 
methods rank it as more complex than most of the net 
modules (with the notable exception of the email package). 
In Beck's TDD book (p. 119), he comments that some 
unittest packages are already too complicated for his tastes.

This patch would make the complexity issue worse.  It takes 
longer to figure out how the use the patch that it does to 
create a small, easy-to-read, special purpose mock object.

Also, I'm concerned that MockObjects tend to create a false 
sense of security in a situation where the actual object 
behavior diverges from the simulated behavior.  Also, to the 
extent that a simulation is simple, it tends to discourage 
adding tests that exercise all the nuances of a real object.  
For example, a MockDatabase may simulate the expected 
replies to some queries but doesn't behave enough like the 
real thing to encourge tests on commits, rollbacks, cache 
flushing, re-ordered tables, etc.

If this doesn't get added to the unittest module, it would 
certainly be worthwhile to post it to the Python Cookbook so 
that advanced users can get to it when they need it.

----------------------------------------------------------------------

Comment By: Matthew Russell (mattruss)
Date: 2003-04-09 19:32

Message:
Logged In: YES 
user_id=737261

I wrote these unittests first before i wrote the code.
Hopefully proves that it works for new style classes and old
(allthought tests are now a little out of date as the updated 
diff uses sets, therefore is 2.3 specific)

----------------------------------------------------------------------

Comment By: Matthew Russell (mattruss)
Date: 2003-04-09 17:53

Message:
Logged In: YES 
user_id=737261

I have made some changes to my patch - i hope it's made 
things clearer (?)

have also replaced 0/1's with False/True where appropriate
added boolean kwd arg to main - exitsOnResult
which if set to false will not do sys.exit (now you can run 
python -i test_mystuff.py using this and not be thrown back 
out to the command line)


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=708125&group_id=5470



More information about the Python-bugs-list mailing list