      # Second pass -- actually create the databases.
      old_names = []
      mirrors = []
  
      for signature, (db_name, aliases) in dependency_ordered(
              test_databases.items(), dependencies):
          test_db_name = None
          # Actually create the database for the first connection
          for alias in aliases:
              connection = connections[alias]
              if test_db_name is None:
 
</s> remove     # Second pass -- actually create the databases.
 </s> add     test_databases = dependency_ordered(test_databases.items(), dependencies)
    test_databases = collections.OrderedDict(test_databases)
    return test_databases, mirrored_aliases


def setup_databases(verbosity, interactive, keepdb=False, debug_sql=False, **kwargs):
    """
    Creates the test databases.
    """
    test_databases, mirrored_aliases = get_unique_databases_and_mirrors()
 </s> remove def setup_databases(verbosity, interactive, keepdb=False, debug_sql=False, **kwargs):
    # First pass -- work out which databases actually need to be created,
    # and which ones are test mirrors or duplicate entries in DATABASES
 </s> add def get_unique_databases_and_mirrors():
    """
    Figure out which databases actually need to be created.

    Deduplicate entries in DATABASES that correspond the same database or are
    configured as test mirrors.

    Returns two values:

    - test_databases: ordered mapping of signatures to (name, list of aliases)
                      where all aliases share the same unerlying database
    - mirrored_aliases: mapping of mirror aliases to original aliases
    """
    for signature, (db_name, aliases) in test_databases.items():
      # Second pass -- actually create the databases.
      old_names = []
      mirrors = []
  
    for signature, (db_name, aliases) in test_databases.items():
    for signature, (db_name, aliases) in test_databases.items():
          test_db_name = None
          # Actually create the database for the first connection
          for alias in aliases:
              connection = connections[alias]
              if test_db_name is None:
keep keep keep keep replace replace keep keep keep keep keep
 Split setup_databases.

It contained two sections separated by comments. It makes more sense to
put each section in its own function. 
django/test/runner.py