-
Notifications
You must be signed in to change notification settings - Fork 408
Open
Description
The problem
factory_boy/__init__.py uses this pattern for its optional sub-packages:
try:
from . import alchemy
except ImportError:
passI have a Django project that uses factory_boy a lot, and imports it even in view code. It also happens that the project has sqlalchemy installed for another tool, but it doesn’t use it directly.
On a importtime-waterfall profile, I noticed that importing factory_boy.alchemy takes ~300ms, nearly all in sqlalchemy and its submodules.
It would be great if importing factory_boy didn’t automatically import sqlalchemy.
Proposed solution
Defer the few sqlalchemy imports in factory.alchemy to the functions that use them. Drop the except ImportError pattern in factory_boy since it should then work regardless of whether sqlalchemy is installed.
Extra notes
None.