[TIP] Mocking a cursor for use with Psycopg2

Tiemo Kieft t.kieft at infinitesimal.nl
Fri Mar 14 01:08:27 PDT 2014

> I'm trying to mock access to my postgres database using the mock framework. I saw the cursor example here. The psycopg2 cursor however does not return the data set but is iterated over example here under result retrieval methods. What would be the best way to mock a cursor which can be called with a function but also be iterated over.

Are you trying to test any specific PG code? Otherwise you might be able to get away with using an in-memory sqlite database for unit tests.

- Tiemo

More information about the testing-in-python mailing list