factory_boy extension with asynchronous ORM support
- python (3.8, 3.9, 3.10)
Install using pip
pip install async_factory_boy
async_factory_boy integrate with Object Relational Mapping (ORM) through
subclass of factory.Factory
. All supported are listed below.
- SQLAlchemy, with
async_factory_boy.factory.sqlalchemy.AsyncSQLAlchemyFactory
from async_factory_boy.factory.sqlalchemy import AsyncSQLAlchemyFactory
class TestModelFactory(AsyncSQLAlchemyFactory):
class Meta:
model = TestModel
session = session
name = Faker("name")
created_at = Faker("date_time")
- Tortoise ORM, with
async_factory_boy.factory.tortoise.AsyncTortoiseFactory
from async_factory_boy.factory.tortoise import AsyncTortoiseFactory
class TestModelFactory(AsyncTortoiseFactory):
class Meta:
model = TestModel
name = Faker("name")
created_at = Faker("date_time")
and factory usage
test = await TestModelFactory.create()
test = await TestModelFactory.build()