Skip to content

Instantly share code, notes, and snippets.

@magopian
Created November 27, 2013 10:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save magopian/7673776 to your computer and use it in GitHub Desktop.
Save magopian/7673776 to your computer and use it in GitHub Desktop.
Little hack for pytest_django: load data in your test database before the tests are run, only if the database is being created and not reused.
import pytest
@pytest.fixture(scope='session')
def _django_db_setup(request, _django_db_setup, _django_cursor_wrapper):
"""Load any data needed for the tests after the database is created.
This "overwrites" pytest_django's own _django_db_setup.
"""
with _django_cursor_wrapper:
if (request.config.getvalue('create_db') or
not request.config.getvalue('reuse_db')):
# we're not reusing the database
#YOUR SETUP HERE, eg: management.call_command('create_categories')
return _django_db_setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment