On Jan 9, 2022, at 09:12, Stefan Chipilov <
chip...@gmail.com> wrote:
>
> Is there a way to automatically rollback any data changes from startup* functions (similar to how changes from setup* functions are automatically rolledback)?
No. A startup function is designed to set things up for all your tests, not individual tests.
> Currently, I workaround this by simply cleaning in a setup* functions. My main concern is that as the number of tests grows, runs will become slower and slower since each test will clean the entire db (this of course, has the benefit of ensuring that each test is independent from others, but that's a different consideration).
Yes, that is the way to do it. The alternative is to separate the functions by naming them differently. So if only 4 out of 10 of your test functions need the startup data, prefix those four and their startup function with some text to separate them from the others. Something like heavy_startup(), heavy_setup(), heavy_test_foo(), heavy_teardown(), heavy_shutdown(). Then run them from a separate script with
SELET * FROM runtests('testschema', ‘^heavy_');
Best,
David