Registry / testing / async-factory-boy

async-factory-boy

JSON →
library1.0.1pypypiunverified

An extension for factory_boy that adds asynchronous ORM support, enabling creation of model instances with async-compatible factories. Current version is 1.0.1, released in 2024. Maintained actively.

pip install async-factory-boy
INSTALL
IMPORT
SIG · ASYNC-FACTORY-BOY
A
async-factory-boy
testingpythonv1.0.1
Install
3.0s avg
Import
Disk
40MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 42.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.0s · import 0.000s · 43MB
40MB installed
● package 40MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AsyncFactory
from async_factory_boy import AsyncFactory
from async_factory_boy import AsyncFactory

Define an async factory for a SQLAlchemy model and create an instance asynchronously.

import asyncio from async_factory_boy.factory.sqlalchemy import AsyncSQLAlchemyModelFactory from factory import Faker from myapp.models import User class UserFactory(AsyncSQLAlchemyModelFactory): class Meta: model = User sqlalchemy_session = None # set per test name = Faker('name') async def test_create_user(db_session): user = await UserFactory.create_async(sqlalchemy_session=db_session) assert user.id is not None
Debug
Known issues
gotchaAsync factories require an explicit async session. Do not rely on a global session; use 'create_async(sqlalchemy_session=session)' or 'build_async()' with session=None.
fix
Always pass a session when creating instances. Use an async fixture to provide the session.
affects: all
gotchaUsing 'create()' (sync) with an async session will fail. Use 'create_async()' instead.
fix
Replace factory.create() with await factory.create_async().
affects: all
deprecatedThe 'AsyncFactory' base class is considered deprecated in favor of specific ORM factories like 'AsyncSQLAlchemyModelFactory'.
fix
Use dedicated factory classes for your ORM (e.g., AsyncSQLAlchemyModelFactory) instead of AsyncFactory.
affects: >=1.0.0
gotcha`Meta.sqlalchemy_session` defined on the factory class is ignored when using `create_async`. It must be passed as an argument.
fix
Always pass `sqlalchemy_session` keyword argument to `create_async()`.
affects: all
Upgrade
Version history
1.0.1latest on PyPI · released Aug 12, 2023
Audit
Dependencies
factory_boyrequiredcore dependency for factory definitions
sqlalchemyoptionalcommonly used async ORM (optional)
databasesoptionalasync database adapter used with SQLAlchemy (optional)
Agent activity
38 hits · last 30 days
node
34
OpenAI (training)
1
Resources
async-factory-boy — pip install async-factory-boy · libregistry