Created
November 27, 2013 10:46
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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