def handle(self, *test_labels, **options):
    # handle south migration in tests
    commands = management.get_commands()
    if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE:
      # point at the core syncdb command when creating tests
      # tests should always be up to date with the most recent model structure
      commands['syncdb'] = 'django.core'
    elif 'south' in settings.INSTALLED_APPS:
      try:
        from south.management.commands import MigrateAndSyncCommand
        commands['syncdb'] = MigrateAndSyncCommand()
        from south.hacks import hacks
        if hasattr(hacks, "patch_flush_during_test_db_creation"):
          hacks.patch_flush_during_test_db_creation()
      except ImportError:
        commands['syncdb'] = 'django.core'

    verbosity = int(options.get('verbosity', 1))
    interactive = options.get('interactive', True)
    failfast = options.get('failfast', False)
    TestRunner = self.get_runner()

    if not inspect.ismethod(TestRunner):
      our_options = {"verbosity" : int(verbosity), "interactive" : interactive, "failfast" : failfast}
      options.update(our_options)
      failures = TestRunner(test_labels, **options)
    else:
      test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast)
      failures = test_runner.run_tests(test_labels)

    if failures:
      sys.exit(bool(failures))
예제 #2
0
def enable_south_migrations():
    #this was taken directly from the pycharm test runner
    management.get_commands()
    if hasattr(settings,
               "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE:
        # point at the core syncdb command when creating tests
        # tests should always be up to date with the most recent model structure
        management._commands['syncdb'] = 'django.core'
    elif 'south' in settings.INSTALLED_APPS:
        try:
            from south.management.commands import MigrateAndSyncCommand

            management._commands['syncdb'] = MigrateAndSyncCommand()
            from south.hacks import hacks

            if hasattr(hacks, "patch_flush_during_test_db_creation"):
                hacks.patch_flush_during_test_db_creation()
        except ImportError:
            management._commands['syncdb'] = 'django.core'
예제 #3
0
    def handle(self, *test_labels, **options):
        interactive = options.get("interactive", True)
        verbosity = int(options.get("verbosity", 1 if interactive else 0))
        reuse_db = options.get("reuse_db", False)
        junit_xml_out = options.get("junit_xml_out")
        coverage_xml_out = options.get("coverage_xml_out")
        coverage_html_out = options.get("coverage_html_out")
        fixed_beef_base = options.get("fixed_beef_base")
        beef = options.get("beef")
        beef_filter = options.get("beef_filter")
        # Check directory for HTML coverage report exists
        if coverage_html_out:
            if not os.path.exists(coverage_html_out):
                os.makedirs(coverage_html_out)
            elif not os.path.isdir(coverage_html_out):
                raise CommandError("%d is not a directory" % coverage_html_out)
            elif not os.access(coverage_html_out, os.W_OK):
                raise CommandError("%d is not writable" % coverage_html_out)

        if (len(test_labels) == 1
                and test_labels[0].startswith("noc.sa.profiles")):
            reuse_db = True
        # Install south migrations hook
        management.get_commands()
        management._commands["syncdb"] = MigrateAndSyncCommand()
        # Disable database flush
        management._commands["flush"] = NoFlushCommand()
        # Run tests
        failures = TestRunner(test_labels=test_labels,
                              verbosity=verbosity,
                              interactive=interactive,
                              reuse_db=reuse_db,
                              junit_xml_out=junit_xml_out,
                              coverage_xml_out=coverage_xml_out,
                              coverage_html_out=coverage_html_out,
                              fixed_beef_base=fixed_beef_base,
                              beef=beef,
                              beef_filter=beef_filter).run()
        if failures:
            sys.exit(1 if failures else 0)