import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.testproject.settings")

from django.test.utils import get_runner
from django.conf import settings

def runtests():
    # Stolen from django/core/management/commands/test.py
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=1, interactive=True)
    failures = test_runner.run_tests(['argonauts'])
    sys.exit(bool(failures))

import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.testproject.settings")

import django
from django.test.utils import get_runner
from django.conf import settings

def runtests():
    if hasattr(django, 'setup'):
        # django >= 1.7
        django.setup()
    # Stolen from django/core/management/commands/test.py
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=1, interactive=True)
    failures = test_runner.run_tests(['argonauts'])
    sys.exit(bool(failures))

Set up the app registry when running tests on django 1.7
Set up the app registry when running tests on django 1.7

(cherry picked from commit 7b3c994758254f16e8f47bf0f13b363d98082f20)
Signed-off-by: Antoine Catton <4589f2e060cef08c47d868a06754605a848a1006@fusionbox.com>

  import os
  import sys
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.testproject.settings")
  
+ import django
  from django.test.utils import get_runner
  from django.conf import settings
  
  def runtests():
+     if hasattr(django, 'setup'):
+         # django >= 1.7
+         django.setup()
      # Stolen from django/core/management/commands/test.py
      TestRunner = get_runner(settings)
      test_runner = TestRunner(verbosity=1, interactive=True)
      failures = test_runner.run_tests(['argonauts'])
      sys.exit(bool(failures))
  
Set up the app registry when running tests on django 1.7
## Code Before:
import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.testproject.settings")

from django.test.utils import get_runner
from django.conf import settings

def runtests():
    # Stolen from django/core/management/commands/test.py
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=1, interactive=True)
    failures = test_runner.run_tests(['argonauts'])
    sys.exit(bool(failures))

## Instruction:
Set up the app registry when running tests on django 1.7
## Code After:
import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.testproject.settings")

import django
from django.test.utils import get_runner
from django.conf import settings

def runtests():
    if hasattr(django, 'setup'):
        # django >= 1.7
        django.setup()
    # Stolen from django/core/management/commands/test.py
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=1, interactive=True)
    failures = test_runner.run_tests(['argonauts'])
    sys.exit(bool(failures))
