コード例 #1
0
ファイル: harvest.py プロジェクト: nathanial/lettuce
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = int(options.get('verbosity', 3))
        no_color = int(options.get('no_color', False))
        apps_to_run = tuple(options.get('apps', '').split(","))
        apps_to_avoid = tuple(options.get('avoid_apps', '').split(","))
        run_server = not options.get('no_server', False)
        test_database = options.get('test_database', False)
        smtp_queue = options.get('smtp_queue', False)
        tags = options.get('tags', None)
        failfast = options.get('failfast', False)
        auto_pdb = options.get('auto_pdb', False)
        threading = options.get('use_threading', True)
        with_summary = options.get('summary_display', False)

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup
                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner
            self._testrunner = get_runner(settings)(interactive=False)
            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            call_command(
                'syncdb',
                verbosity=0,
                interactive=False,
            )
            if migrate_south:
                call_command(
                    'migrate',
                    verbosity=0,
                    interactive=False,
                )

        settings.DEBUG = options.get('debug', False)

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options['port'], threading=threading)

        if run_server:
            try:
                server.start()
            except LettuceServerException, e:
                raise SystemExit(e)
コード例 #2
0
ファイル: harvest.py プロジェクト: adw0rd/lettuce
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = int(options.get('verbosity', 3))
        if options.get('no_color', False) and verbosity is 3:
            verbosity = 4
        settings.DEBUG = options.get('debug', False)
        settings.LETTUCE_BROWSER = options.get('browser', 'firefox')
        settings.LETTUCE_FAILED_STEP_SLEEP = options.get('failed_step_sleep')
        settings.DEFAULT_TABLESPACE = options.get('tablespace')
        settings.DISABLE_JSCOMPILE = options.get('disable_jscompile')
        settings.LETTUCE_BY_STEP = options.get('by_step', False)

        apps_to_run = tuple(options.get('apps', '').split(","))
        apps_to_avoid = tuple(options.get('avoid_apps', '').split(","))
        run_server = not options.get('no_server', False)
        test_database = options.get('test_database', False)
        smtp_queue = options.get('smtp_queue', False)
        tags = options.get('tags', None)
        failfast = options.get('failfast', False)
        auto_pdb = options.get('auto_pdb', False)
        threading = options.get('use_threading', True)
        with_summary = options.get('summary_display', False)

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup
                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner
            self._testrunner = get_runner(settings)(interactive=False)
            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            call_command('syncdb', verbosity=0, interactive=False,)
            if migrate_south:
               call_command('migrate', verbosity=0, interactive=False,)


        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options['port'], threading=threading)

        if run_server:
            try:
                server.start()
            except LettuceServerException, e:
                raise SystemExit(e)
コード例 #3
0
ファイル: harvest.py プロジェクト: 360youlun/lettuce
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = int(options.get("verbosity", 3))
        apps_to_run = tuple(options.get("apps", "").split(","))
        apps_to_avoid = tuple(options.get("avoid_apps", "").split(","))
        run_server = not options.get("no_server", False)
        test_database = options.get("test_database", False)
        smtp_queue = options.get("smtp_queue", False)
        tags = options.get("tags", None)
        failfast = options.get("failfast", False)
        auto_pdb = options.get("auto_pdb", False)
        threading = options.get("use_threading", True)
        with_summary = options.get("summary_display", False)

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup

                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner

            self._testrunner = get_runner(settings)(interactive=False)
            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            call_command("syncdb", verbosity=0, interactive=False)
            if migrate_south:
                call_command("migrate", verbosity=0, interactive=False)

        settings.DEBUG = options.get("debug", False)

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options["port"], threading=threading)

        if run_server:
            try:
                server.start()
            except LettuceServerException, e:
                raise SystemExit(e)
コード例 #4
0
ファイル: harvest.py プロジェクト: atykhonov/lettuce
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = int(options.get('verbosity', 4))
        apps_to_run = tuple(options.get('apps', '').split(","))
        apps_to_avoid = tuple(options.get('avoid_apps', '').split(","))
        run_server = not options.get('no_server', False)
        test_database = options.get('test_database', False)
        smtp_queue = options.get('smtp_queue', False)
        tags = options.get('tags', None)
        failfast = options.get('failfast', False)
        auto_pdb = options.get('auto_pdb', False)
        with_summary = options.get('summary_display', False)

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup
                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner
            self._testrunner = get_runner(settings)(interactive=False)
            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            call_command('syncdb', verbosity=0, interactive=False,)
            if migrate_south:
               call_command('migrate', verbosity=0, interactive=False,)

        settings.DEBUG = options.get('debug', False)

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options['port'])

        if run_server:
            try:
                server.start()
            except LettuceServerException, e:
                raise SystemExit(e)
コード例 #5
0
ファイル: harvest.py プロジェクト: MikeHibbert/lettuce
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = options['verbosity']
        no_color = options.get('no_color', False)
        apps_to_run = tuple(options['apps'].split(","))
        apps_to_avoid = tuple(options['avoid_apps'].split(","))
        run_server = not options['no_server']
        test_database = options['test_database']
        smtp_queue = options['smtp_queue']
        tags = options['tags']
        failfast = options['failfast']
        auto_pdb = options['auto_pdb']
        threading = options['use_threading']

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup
                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner
            self._testrunner = get_runner(settings)(interactive=False)
            
            if DJANGO_VERSION > StrictVersion('1.10'):
                self._testrunner.teardown_test_environment()
                
            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            if DJANGO_VERSION < StrictVersion('1.7'):
                call_command('syncdb', verbosity=0, interactive=False,)
                if migrate_south:
                   call_command('migrate', verbosity=0, interactive=False,)
            else:
                call_command('migrate', verbosity=0, interactive=False,)

        settings.DEBUG = options.get('debug', False)

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options['port'], threading=threading)

        if run_server:
            try:
                server.start()
            except LettuceServerException as e:
                raise CommandError("Couldn't start Django server: %s" % e)

        os.environ['SERVER_NAME'] = str(server.address)
        os.environ['SERVER_PORT'] = str(server.port)

        failed = False

        registry.call_hook('before', 'harvest', locals())
        results = []
        try:
            for path in paths:
                app_module = None
                if isinstance(path, tuple) and len(path) is 2:
                    path, app_module = path

                if app_module is not None:
                    registry.call_hook('before_each', 'app', app_module)

                runner = Runner(path, options.get('scenarios'),
                                verbosity, no_color,
                                enable_xunit=options.get('enable_xunit'),
                                enable_subunit=options.get('enable_subunit'),
                                enable_jsonreport=options.get('enable_jsonreport'),
                                xunit_filename=options.get('xunit_file'),
                                subunit_filename=options.get('subunit_file'),
                                jsonreport_filename=options.get('jsonreport_file'),
                                tags=tags, failfast=failfast, auto_pdb=auto_pdb,
                                root_dir=path,
                                smtp_queue=smtp_queue)

                result = runner.run()
                if app_module is not None:
                    registry.call_hook('after_each', 'app', app_module, result)

                results.append(result)
                if not result or result.steps != result.steps_passed:
                    failed = True
        except LettuceRunnerError:
            failed = True

        except Exception as e:
            failed = True
            traceback.print_exc(e)

        finally:
            summary = SummaryTotalResults(results)
            summary.summarize_all()
            registry.call_hook('after', 'harvest', summary)

            if test_database:
                self._testrunner.teardown_databases(self._old_db_config)

            teardown_test_environment()
            server.stop(failed)

            if failed:
                raise CommandError("Lettuce tests failed.")
コード例 #6
0
ファイル: harvest.py プロジェクト: Acetonen/lettuce-py3
    def handle(self, *args, **options):
        setup_test_environment()
        settings.DEBUG = options.get('debug', False)
        settings.LETTUCE_BROWSER = options.get('browser', 'chrome')
        settings.LETTUCE_FAILED_STEP_SLEEP = options.get('failed_step_sleep')
        settings.DEFAULT_TABLESPACE = options.get('tablespace')
        settings.DISABLE_JSCOMPILE = options.get('disable_jscompile')
        settings.LETTUCE_BY_STEP = options.get('by_step', False)
        settings.LETTUCE_HEADLESS = options.get('headless', False)

        verbosity = int(options.get('verbosity', 3))
        no_color = int(options.get('no_color', False))
        apps_to_run = tuple(options.get('apps', '').split(","))
        apps_to_avoid = tuple(options.get('avoid_apps', '').split(","))
        run_server = not options.get('no_server', False)
        test_database = options.get('test_database', False)
        smtp_queue = options.get('smtp_queue', False)
        tags = options.get('tags', None)
        failfast = options.get('failfast', False)
        auto_pdb = options.get('auto_pdb', False)
        threading = options.get('use_threading', True)
        with_summary = options.get('summary_display', False)
        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup
                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner
            self._testrunner = get_runner(settings)(interactive=False)

            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            call_command(
                'syncdb',
                verbosity=0,
                interactive=False,
            )
            if migrate_south:
                call_command(
                    'migrate',
                    verbosity=0,
                    interactive=False,
                )

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        if not paths:
            paths = options.get('paths', [])
        server = get_server(port=options['port'], threading=threading)
        os.environ['REMOTE_HOST'] = options['host']
        if run_server:
            try:
                server.start()
            except LettuceServerException as e:
                raise SystemExit(e)

        os.environ['SERVER_NAME'] = str(server.address)
        os.environ['SERVER_PORT'] = str(server.port)

        failed = False

        registry.call_hook('before', 'harvest', locals())
        results = []
        try:
            for path in paths:
                app_module = None
                if isinstance(path, tuple) and len(path) is 2:
                    path, app_module = path

                if app_module is not None:
                    registry.call_hook('before_each', 'app', app_module)

                runner = Runner(path,
                                options.get('scenarios'),
                                verbosity,
                                no_color,
                                enable_xunit=options.get('enable_xunit'),
                                enable_subunit=options.get('enable_subunit'),
                                xunit_filename=options.get('xunit_file'),
                                subunit_filename=options.get('subunit_file'),
                                tags=tags,
                                failfast=failfast,
                                auto_pdb=auto_pdb,
                                smtp_queue=smtp_queue)

                result = runner.run()
                if app_module is not None:
                    registry.call_hook('after_each', 'app', app_module, result)

                results.append(result)
                if not result or result.steps != result.steps_passed:
                    failed = True
        except SystemExit as e:
            failed = e.code

        except Exception as e:
            failed = True
            import traceback
            traceback.print_exc(0)

        finally:
            summary = SummaryTotalResults(results)
            summary.summarize_all()
            registry.call_hook('after', 'harvest', summary)

            if test_database:
                self._testrunner.teardown_databases(self._old_db_config)

            teardown_test_environment()
            server.stop(failed)

            raise SystemExit(int(failed))
コード例 #7
0
ファイル: harvest.py プロジェクト: phelios/lettuce
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = int(options.get('verbosity', 3))
        no_color = int(options.get('no_color', False))
        apps_to_run = tuple(options.get('apps', '').split(","))
        apps_to_avoid = tuple(options.get('avoid_apps', '').split(","))
        run_server = not options.get('no_server', False)
        test_database = options.get('test_database', False)
        smtp_queue = options.get('smtp_queue', False)
        tags = options.get('tags', None)
        failfast = options.get('failfast', False)
        auto_pdb = options.get('auto_pdb', False)
        threading = options.get('use_threading', True)
        with_summary = options.get('summary_display', False)

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup
                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner
            self._testrunner = get_runner(settings)(interactive=False)
            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            call_command('syncdb', verbosity=0, interactive=False,)
            if migrate_south:
               call_command('migrate', verbosity=0, interactive=False,)

        settings.DEBUG = options.get('debug', False)

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options['port'], threading=threading)

        if run_server:
            try:
                server.start()
            except LettuceServerException as e:
                raise SystemExit(e)

        os.environ['SERVER_NAME'] = str(server.address)
        os.environ['SERVER_PORT'] = str(server.port)

        failed = False

        registry.call_hook('before', 'harvest', locals())
        results = []
        try:
            for path in paths:
                app_module = None
                if isinstance(path, tuple) and len(path) is 2:
                    path, app_module = path

                if app_module is not None:
                    registry.call_hook('before_each', 'app', app_module)

                runner = Runner(path, options.get('scenarios'),
                                verbosity, no_color,
                                enable_xunit=options.get('enable_xunit'),
                                enable_subunit=options.get('enable_subunit'),
                                xunit_filename=options.get('xunit_file'),
                                subunit_filename=options.get('subunit_file'),
                                tags=tags, failfast=failfast, auto_pdb=auto_pdb,
                                smtp_queue=smtp_queue)

                result = runner.run()
                if app_module is not None:
                    registry.call_hook('after_each', 'app', app_module, result)

                results.append(result)
                if not result or result.steps != result.steps_passed:
                    failed = True
        except SystemExit as e:
            failed = e.code

        except Exception as e:
            failed = True
            import traceback
            traceback.print_exc(e)

        finally:
            summary = SummaryTotalResults(results)
            summary.summarize_all()
            registry.call_hook('after', 'harvest', summary)

            if test_database:
                self._testrunner.teardown_databases(self._old_db_config)

            teardown_test_environment()
            server.stop(failed)

            raise SystemExit(int(failed))
コード例 #8
0
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = options['verbosity']
        no_color = options.get('no_color', False)
        apps_to_run = tuple(options['apps'].split(","))
        apps_to_avoid = tuple(options['avoid_apps'].split(","))
        run_server = not options['no_server']
        test_database = options['test_database']
        smtp_queue = options['smtp_queue']
        tags = options['tags']
        failfast = options['failfast']
        auto_pdb = options['auto_pdb']
        threading = options['use_threading']

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup
                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner
            self._testrunner = get_runner(settings)(interactive=False)

            if DJANGO_VERSION > StrictVersion('1.10'):
                self._testrunner.teardown_test_environment()

            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            if DJANGO_VERSION < StrictVersion('1.7'):
                call_command(
                    'syncdb',
                    verbosity=0,
                    interactive=False,
                )
                if migrate_south:
                    call_command(
                        'migrate',
                        verbosity=0,
                        interactive=False,
                    )
            else:
                call_command(
                    'migrate',
                    verbosity=0,
                    interactive=False,
                )

        settings.DEBUG = options.get('debug', False)

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options['port'], threading=threading)

        if run_server:
            try:
                server.start()
            except LettuceServerException as e:
                raise CommandError("Couldn't start Django server: %s" % e)

        os.environ['SERVER_NAME'] = str(server.address)
        os.environ['SERVER_PORT'] = str(server.port)

        failed = False

        registry.call_hook('before', 'harvest', locals())
        results = []
        try:
            for path in paths:
                app_module = None
                if isinstance(path, tuple) and len(path) is 2:
                    path, app_module = path

                if app_module is not None:
                    registry.call_hook('before_each', 'app', app_module)

                runner = Runner(
                    path,
                    options.get('scenarios'),
                    verbosity,
                    no_color,
                    enable_xunit=options.get('enable_xunit'),
                    enable_subunit=options.get('enable_subunit'),
                    enable_jsonreport=options.get('enable_jsonreport'),
                    xunit_filename=options.get('xunit_file'),
                    subunit_filename=options.get('subunit_file'),
                    jsonreport_filename=options.get('jsonreport_file'),
                    tags=tags,
                    failfast=failfast,
                    auto_pdb=auto_pdb,
                    root_dir=path,
                    smtp_queue=smtp_queue)

                result = runner.run()
                if app_module is not None:
                    registry.call_hook('after_each', 'app', app_module, result)

                results.append(result)
                if not result or result.steps != result.steps_passed:
                    failed = True
        except LettuceRunnerError:
            failed = True

        except Exception as e:
            failed = True
            traceback.print_exc(e)

        finally:
            summary = SummaryTotalResults(results)
            summary.summarize_all()
            registry.call_hook('after', 'harvest', summary)

            if test_database:
                self._testrunner.teardown_databases(self._old_db_config)

            teardown_test_environment()
            server.stop(failed)

            if failed:
                raise CommandError("Lettuce tests failed.")
コード例 #9
0
ファイル: harvest.py プロジェクト: anrojaslat/lettuce
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = options["verbosity"]
        no_color = options.get("no_color", False)
        apps_to_run = tuple(options["apps"].split(","))
        apps_to_avoid = tuple(options["avoid_apps"].split(","))
        run_server = not options["no_server"]
        test_database = options["test_database"]
        smtp_queue = options["smtp_queue"]
        tags = options["tags"]
        failfast = options["failfast"]
        auto_pdb = options["auto_pdb"]
        threading = options["use_threading"]

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup

                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner

            self._testrunner = get_runner(settings)(interactive=False)
            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            if DJANGO_VERSION < StrictVersion("1.7"):
                call_command("syncdb", verbosity=0, interactive=False)
                if migrate_south:
                    call_command("migrate", verbosity=0, interactive=False)
            else:
                call_command("migrate", verbosity=0, interactive=False)

        settings.DEBUG = options.get("debug", False)

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options["port"], threading=threading)

        if run_server:
            try:
                server.start()
            except LettuceServerException as e:
                raise CommandError("Couldn't start Django server: %s" % e)

        os.environ["SERVER_NAME"] = str(server.address)
        os.environ["SERVER_PORT"] = str(server.port)

        failed = False

        registry.call_hook("before", "harvest", locals())
        results = []
        try:
            for path in paths:
                app_module = None
                if isinstance(path, tuple) and len(path) is 2:
                    path, app_module = path

                if app_module is not None:
                    registry.call_hook("before_each", "app", app_module)

                runner = Runner(
                    path,
                    options.get("scenarios"),
                    verbosity,
                    no_color,
                    enable_xunit=options.get("enable_xunit"),
                    enable_subunit=options.get("enable_subunit"),
                    enable_jsonreport=options.get("enable_jsonreport"),
                    xunit_filename=options.get("xunit_file"),
                    subunit_filename=options.get("subunit_file"),
                    jsonreport_filename=options.get("jsonreport_file"),
                    tags=tags,
                    failfast=failfast,
                    auto_pdb=auto_pdb,
                    smtp_queue=smtp_queue,
                )

                result = runner.run()
                if app_module is not None:
                    registry.call_hook("after_each", "app", app_module, result)

                results.append(result)
                if not result or result.steps != result.steps_passed:
                    failed = True
        except LettuceRunnerError:
            failed = True

        except Exception as e:
            failed = True
            traceback.print_exc(e)

        finally:
            summary = SummaryTotalResults(results)
            summary.summarize_all()
            registry.call_hook("after", "harvest", summary)

            if test_database:
                self._testrunner.teardown_databases(self._old_db_config)

            teardown_test_environment()
            server.stop(failed)

            if failed:
                raise CommandError("Lettuce tests failed.")
コード例 #10
0
# -*- coding: utf-8 -*-
from lettuce.django import get_server
get_server()
from lettuce.django import django_url
from lettuce import before, after, world, step
from django.conf import settings
from django.test import client
from smart_sa.intervention.models import Intervention, Participant, ClientSession, Activity
import os
import sys

import time
try:
    from lxml import html
    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
    from selenium.common.exceptions import NoSuchElementException
    from selenium.webdriver.common.keys import Keys
    import selenium
except:
    pass


@before.harvest
def setup_browser(variables):
    browser = getattr(settings, 'BROWSER', None)
    if browser == 'Headless':
        # this should really be called 'world.browser'
        # but we'll fix that later
        world.firefox = webdriver.PhantomJS()
    else:
コード例 #11
0
ファイル: harvest.py プロジェクト: smilicic/lettuce
    def handle(self, *args, **options):
        setup_test_environment()

        verbosity = int(options.get('verbosity', 3))
        no_color = int(options.get('no_color', False))
        apps_to_run = tuple(options.get('apps', '').split(","))
        apps_to_avoid = tuple(options.get('avoid_apps', '').split(","))
        run_server = not options.get('no_server', False)
        test_database = options.get('test_database', False)
        smtp_queue = options.get('smtp_queue', False)
        tags = options.get('tags', None)
        failfast = options.get('failfast', False)
        auto_pdb = options.get('auto_pdb', False)
        threading = options.get('use_threading', True)
        with_summary = options.get('summary_display', False)
        processes = int(options.get('processes', 1))

        if test_database:
            migrate_south = getattr(settings, "SOUTH_TESTS_MIGRATE", True)
            try:
                from south.management.commands import patch_for_test_db_setup
                patch_for_test_db_setup()
            except:
                migrate_south = False
                pass

            from django.test.utils import get_runner
            self._testrunner = get_runner(settings)(interactive=False)
            self._testrunner.setup_test_environment()
            self._old_db_config = self._testrunner.setup_databases()

            if StrictVersion(django.get_version()) < StrictVersion('1.7'):
                call_command(
                    'syncdb',
                    verbosity=0,
                    interactive=False,
                )
                if migrate_south:
                    call_command(
                        'migrate',
                        verbosity=0,
                        interactive=False,
                    )
            else:
                call_command(
                    'migrate',
                    verbosity=0,
                    interactive=False,
                )

        settings.DEBUG = options.get('debug', False)

        paths = self.get_paths(args, apps_to_run, apps_to_avoid)
        server = get_server(port=options['port'], threading=threading)

        if run_server:
            try:
                server.start()
            except LettuceServerException as e:
                raise SystemExit(e)

        os.environ['SERVER_NAME'] = str(server.address)
        os.environ['SERVER_PORT'] = str(server.port)

        failed = False

        registry.call_hook('before', 'harvest', locals())
        results = []

        try:
            for path in paths:
                app_module = None
                if isinstance(path, tuple) and len(path) is 2:
                    path, app_module = path

                if app_module is not None:
                    registry.call_hook('before_each', 'app', app_module)

                if processes > 1:
                    runner = ParallelRunner(
                        path,
                        options.get('scenarios'),
                        verbosity,
                        no_color,
                        enable_xunit=options.get('enable_xunit'),
                        enable_subunit=options.get('enable_subunit'),
                        xunit_filename=options.get('xunit_file'),
                        subunit_filename=options.get('subunit_file'),
                        failfast=failfast,
                        auto_pdb=auto_pdb,
                        tags=tags,
                        workers=processes)
                else:
                    runner = Runner(
                        path,
                        options.get('scenarios'),
                        verbosity,
                        no_color,
                        enable_xunit=options.get('enable_xunit'),
                        enable_subunit=options.get('enable_subunit'),
                        xunit_filename=options.get('xunit_file'),
                        subunit_filename=options.get('subunit_file'),
                        tags=tags,
                        failfast=failfast,
                        auto_pdb=auto_pdb,
                        smtp_queue=smtp_queue)

                result = runner.run()
                if app_module is not None:
                    registry.call_hook('after_each', 'app', app_module, result)

                results.append(result)
                if not result or result.steps != result.steps_passed:
                    failed = True

        except SystemExit as e:
            failed = e.code

        except Exception as e:
            failed = True
            import traceback
            traceback.print_exc(e)

        finally:
            registry.call_hook('after', 'harvest', results)

            if test_database:
                self._testrunner.teardown_databases(self._old_db_config)

            teardown_test_environment()
            server.stop(failed)

            raise SystemExit(int(failed))