[TIP] Mocking a cursor for use with Psycopg2

Randy Syring randy at thesyrings.us
Fri Mar 14 08:28:53 PDT 2014

On 03/14/2014 11:07 AM, Tiemo Kieft wrote:
> Ideally you’d have each unit test running in a clean environment, which means creating a new database per test case.

Personally, I think this is overkill.  We approach this by making tests 
responsible for cleaning and/or setting up any tables they need.  So, if 
I have to have certain data in my orders table, then I'm responsible for:

# delete all orders and anything dependent on orders, this method is 
responsible for knowing what depends on orders and calling 
dependent_object.delete_all_cascaded() for those tables.  But only one 
level deep since the dependent objects are also responsible for taking 
care of dependencies.


# create order with sane defaults, pass in parameters to change values 
that need to be updated for testing.

FWIW.  :)

*Randy Syring*
Husband | Father | Redeemed Sinner

/"For what does it profit a man to gain the whole world
and forfeit his soul?" (Mark 8:36 ESV)/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140314/f4630c77/attachment.htm>

More information about the testing-in-python mailing list