From 0e3ba72701b1c802fab1ce1de471c6c41b07e141 Mon Sep 17 00:00:00 2001 From: Caleb Brown Date: Fri, 30 Nov 2012 14:22:01 +1100 Subject: [PATCH 1/2] Add support for using south migrations during tests. --- pytest_django/plugin.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 7b894dce4..5bdf9e4f2 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -76,16 +76,21 @@ def pytest_addoption(parser): 'option will be ignored if not --reuse-db is given.') -def _disable_south_management_command(): - management.get_commands() - # make sure `south` migrations are disabled - management._commands['syncdb'] = 'django.core' +def _handle_south_management_command(): + try: + from south.management.commands import patch_for_test_db_setup + except ImportError: + management.get_commands() + # make sure `south` migrations are disabled + management._commands['syncdb'] = 'django.core' + else: + patch_for_test_db_setup() def pytest_sessionstart(session): global suite_runner, old_db_config - _disable_south_management_command() + _handle_south_management_command() suite_runner = get_runner(session.config) suite_runner.setup_test_environment() From 95a414104a2b726ff1c076eb2f7e70e2bef65da9 Mon Sep 17 00:00:00 2001 From: Caleb Brown Date: Fri, 30 Nov 2012 14:32:44 +1100 Subject: [PATCH 2/2] Make the comments around the south migration handling code clearer. --- pytest_django/plugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 5bdf9e4f2..ff80c92f0 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -78,10 +78,11 @@ def pytest_addoption(parser): def _handle_south_management_command(): try: + # if `south` >= 0.7.1 we can use the test helper from south.management.commands import patch_for_test_db_setup except ImportError: + # if `south` < 0.7.1 make sure it's migrations are disabled management.get_commands() - # make sure `south` migrations are disabled management._commands['syncdb'] = 'django.core' else: patch_for_test_db_setup()