Testing postgresql in unit tests – mocking and unit test libraries

I am going to start a project in Python which will deal with a lot of database operations and this means I have to write tons of unit tests.

I was reading about mocking database connections, cursors and executing sql queries for my unit tests (that are going to come up).

I hit upon different libraries to do this:

  1. https://github.com/tk0miya/testing.postgresql – which seems best as I can spin up a db instance in userspace, but seems unmaintained with the last commit in 2017. (As an aside, this is what I do for my Golang projects – spinning up an entire Postgres instance in Docker using the Golang Docker APIs as setup)

  2. Many blogs recommend pytest-postgresql, however, I have not been able to understand how to use this. This seems to be very active project with the last commit just a few months ago.

  3. Some blogs also suggest pytest-pgsql, and similar to above, I have not been able to understand how to set this up and use it.

Any other suggestions would also be welcome.

Source: Python Questions