Integration Tests

Let’s learn about how to use PostgreSQL as a repository and test it.

At this point, we can create real tests in the test_postgresrepo.py file and replace our test_dummy function. All tests receive the app_configuration, pg_session, and pg_test_data fixtures. The first fixture allows us to initialize the PostgresRepo class with the proper parameters. The second fixture creates the database with our test data. Finally, the third fixture contains the database.

Impact on our test cases

The tests for this repository are a copy of the ones we created for our MemRepo repository. This is not surprising. Usually, we want to test the very same conditions, regardless of the storage system we are currently using. However, toward the end of this chapter, we’ll see that, while these files are initially the same, they can evolve differently. This can be due to the occurrence of bugs or corner cases resulting from specific implementations, such as in-memory storage, PostgreSQL, etc.

Get hands-on with 1200+ tech skills courses.