2

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.

krish7919
  • 892
  • 2
  • 13
  • 30
  • In the end, instead of mocking things, I just spin up a postgresql docker container for UTs in the test code during startup, populate that with test data, and use it. No need to use mocking at all. – krish7919 Oct 07 '21 at 14:57

0 Answers0