schireson / pytest-mock-resources

Pytest Fixtures that let you actually test against external resource (Postgres, Mongo, Redshift...) dependent code.
https://pytest-mock-resources.readthedocs.io/en/latest/quickstart.html
MIT License
179 stars 19 forks source link

feat: Amortize the cost of database setup in postgres through the use of template databases. #151

Closed DanCardin closed 2 years ago

DanCardin commented 2 years ago

Today we create a brand new test database for each test, it's completely empty, and then we populate the database with ordered_actions to fill it with the DDL/data we need in the tests.

The idea is that we make use of postgres' template database feature which replicates the state of a database from another database (which happens always, just your default template template1 is empty by default). We avoid tons of python/sqlalchemy stuff, and presumably postgres is optimized to do what it does quickly.

Large test suite

The above is with -n 4 parallelism. the numbers get better as you increase parallelism. I stopped the original suite after 40 mins without parallelism, whereas with this PR it took 17m (faster than the parallelized pre-PR version)

For pytest-mock-resources' own test suite, it's essentially the same or slightly slower overall because there necessarily tends to be close to a 1-to-1 correspondence between each test and its fixture to test PMR's fixture args/features.

luke-mino-altherr commented 2 years ago

i'm assuming youll fix tests?

DanCardin commented 2 years ago

yea, it was all passing a few moments ago, i added a new test and broke some stuff.