SQLAlchemy + FactoryBoy: Passing arbitrary sessions to factories

SQLAlchemy + FactoryBoy: Passing arbitrary sessions to factories

In work projects in the past, my team would try to avoid dealing with the complexity of SQLAlchemy database sessions by making one global session that every module referenced. It made things easy and straightforward and it played nice with FactoryBoy - whose factories seem to work quite well under those conditions. Going into building lobit.io, I tried to do things the same way, but as the code base and the number of unit tests grew, I kept facing what seemed to be an unquashable avalanche of OperationalErrors griping about "Too many connections". I implemented an overhaul…

Read More