Skip to content

Is there a good way to call the seeder from within a pytest fixture? #17

Description

@johnoooo

I want to seed an in-memory Sqlite3 database as part of a pytest fixture.

The documentation of flask-seeder just describes calling the seeder via the CLI. A quick trial to call seed_run() seems to work with some nasty hacks, but is obviously not the intended way of calling.

My current code (excerpt):

from flask_migrate import upgrade
from flask_seeder.cli import seed_run

@pytest.fixture(name="app")
def fixture_app():
    app = create_app(TestingConfig())

    # setup the database
    with app.app_context():
        upgrade()
        seed_run(args=[], standalone_mode=False)

    yield app

Are there better ways to achieve this task with flask-seeder?

As there is apparently no other entry point in the code for running the seeds, might this be a feature to add?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions