def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    setup_test_environment()

    settings.DEBUG = False
    suite = unittest.TestSuite()

    if test_labels:
        for label in test_labels:
            if '.' in label:
                suite.addTest(build_test(label))
            else:
                app = get_app(label)
                suite.addTest(build_suite(app))
    else:
        for app in get_apps():
            suite.addTest(build_suite(app))

    for test in extra_tests:
        suite.addTest(test)

    old_name = settings.DATABASE_NAME
    from django.db import connection
    connection.creation.create_test_db(verbosity, autoclobber=not interactive)
    result = XMLTestRunner(verbosity=verbosity).run(suite)
    connection.creation.destroy_test_db(old_name, verbosity)

    teardown_test_environment()

    return len(result.failures) + len(result.errors)
示例#2
0
def run_the_old_way(extra_tests, kwargs, test_labels, verbosity):
  from django.test.simple import build_suite, build_test, get_app, get_apps, \
    setup_test_environment, teardown_test_environment

  setup_test_environment()
  settings.DEBUG = False
  suite = unittest.TestSuite()
  if test_labels:
    for label in test_labels:
      if '.' in label:
        suite.addTest(build_test(label))
      else:
        app = get_app(label)
        suite.addTest(build_suite(app))
  else:
    for app in get_apps():
      suite.addTest(build_suite(app))
  for test in extra_tests:
    suite.addTest(test)
  suite = reorder_suite(suite, (TestCase,))
  old_name = settings.DATABASE_NAME
  from django.db import connection

  connection.creation.create_test_db(verbosity, autoclobber=False)
  result = DjangoTeamcityTestRunner().run(suite, **kwargs)
  connection.creation.destroy_test_db(old_name, verbosity)
  teardown_test_environment()
  return len(result.failures) + len(result.errors)
示例#3
0
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    """Run the unit tests without using the ORM.
    """
    setup_test_environment()

    settings.DEBUG = False
    settings.DATABASE_SUPPORTS_TRANSACTIONS = False
    suite = unittest.TestSuite()

    if test_labels:
        for label in test_labels:
            if '.' in label:
                suite.addTest(build_test(label))
            else:
                app = get_app(label)
                suite.addTest(build_suite(app))
    else:
        for app in get_apps():
            suite.addTest(build_suite(app))

    for test in extra_tests:
        suite.addTest(test)

    suite = reorder_suite(suite, (TestCase, ))

    runner = unittest.TextTestRunner(verbosity=verbosity)
    result = runner.run(suite)

    teardown_test_environment()

    return len(result.failures) + len(result.errors)
示例#4
0
 def setup_test_environment(self, **kwargs):
     simple.setup_test_environment()
     settings.DEBUG=False
     settings.TEMPLATE_CONTEXT_PROCESSORS = list(settings.TEMPLATE_CONTEXT_PROCESSORS) + [
         'django_testing_fixes.testing_context.extra'
     ]
     unittest.installHandler()
示例#5
0
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    """Run the unit tests without using the ORM.
    """
    setup_test_environment()

    settings.DEBUG = False
    settings.DATABASE_SUPPORTS_TRANSACTIONS = False
    suite = unittest.TestSuite()

    if test_labels:
        for label in test_labels:
            if '.' in label:
                suite.addTest(build_test(label))
            else:
                app = get_app(label)
                suite.addTest(build_suite(app))
    else:
        for app in get_apps():
            suite.addTest(build_suite(app))

    for test in extra_tests:
        suite.addTest(test)

    suite = reorder_suite(suite, (TestCase,))

    runner = unittest.TextTestRunner(verbosity=verbosity)
    result = runner.run(suite)

    teardown_test_environment()

    return len(result.failures) + len(result.errors)
def run_tests(test_labels, verbosity=1, interactive=False, extra_tests=[],
              **kwargs):
  """
  Run the unit tests for all the test labels in the provided list.
  Labels must be of the form:
   - app.TestClass.test_method
      Run a single specific test method
   - app.TestClass
      Run all the test methods in a given class
   - app
      Search for doctests and unittests in the named application.

  When looking for tests, the test runner will look in the models and
  tests modules for the application.

  A list of 'extra' tests may also be provided; these tests
  will be added to the test suite.

  Returns the number of tests that failed.
  """
  TeamcityServiceMessages(sys.stdout).testMatrixEntered()
  if VERSION[1] > 1:
    return DjangoTeamcityTestRunner().run_tests(test_labels,
      extra_tests=extra_tests, **kwargs)

  setup_test_environment()

  settings.DEBUG = False
  suite = unittest.TestSuite()

  if test_labels:
    for label in test_labels:
      if '.' in label:
        suite.addTest(build_test(label))
      else:
        app = get_app(label)
        suite.addTest(build_suite(app))
  else:
    for app in get_apps():
      suite.addTest(build_suite(app))

  for test in extra_tests:
    suite.addTest(test)

  suite = reorder_suite(suite, (TestCase,))

  old_name = settings.DATABASE_NAME
  from django.db import connection

  connection.creation.create_test_db(verbosity, autoclobber=False)

  result = DjangoTeamcityTestRunner().run(suite, **kwargs)
  connection.creation.destroy_test_db(old_name, verbosity)

  teardown_test_environment()

  return len(result.failures) + len(result.errors)
示例#7
0
import os,sys

#hack
path = os.path.abspath(__file__)
for i in range(3):
    path = os.path.dirname(path)

sys.path.insert(0, path)
                 
os.environ['DJANGO_SETTINGS_MODULE'] = 'activities.tests.settings'



from django.test import simple
from django.db import connection
from django.db.models.loading import load_app
from django.conf import settings
import unittest


simple.setup_test_environment()
suite = simple.build_suite(load_app('activities.tests'))
old_name = settings.DATABASE_NAME
connection.creation.create_test_db(9)
result = unittest.TextTestRunner(verbosity=9).run(suite)
connection.creation.destroy_test_db(old_name, 9)
simple.teardown_test_environment()