How to Generate Fixtures from Database with SqlAlchemy

I'm starting to write tests with Flask-SQLAlchemy, and I'd like to add some fixtures for those. I have plenty of good data for that in my development database and a lot of tables so writing data manually would get annoying. I'd really like to just sample data from the dev database into fixtures and then use those. What's a good way to do this?


i would use factory boy

to create a model factory you just do:

import factory
from . import models

class UserFactory(factory.Factory):
    class Meta:
        model = models.User

    first_name = 'John'
    last_name = 'Doe'
    admin = False

then to create instances:

UserFactory.create()

to add static data just give as kwarg to create

UserFactory.create(name='hank')

so to seed a bunch of stuff throw that in a for loop. :)