Repository: django/django
File: django/db/backends/base/creation.py (Python)

Code before:
        with self._nodb_cursor() as cursor:
            cursor.execute(
                "DROP DATABASE %s" % self.connection.ops.quote_name(test_database_name)
            )

    def mark_expected_failures_and_skips(self):
        """
        Mark tests in Django's test suite which are expected failures on this
        database and test which should be skipped on this database.
        """
        for test_name in self.connection.features.django_test_expected_failures:
            self._mark_test(test_name)
        for reason, tests in self.connection.features.django_test_skips.items():
            for test_name in tests:
                self._mark_test(test_name, reason)

    def _mark_test(self, test_name, skip_reason=None):
        # Only load unittest if we're actually testing.
        from unittest import expectedFailure, skip

        module_or_class_name, _, name_to_mark = test_name.rpartition(".")
        test_app = test_name.split(".")[0]
        # Importing a test app that isn't installed raises RuntimeError.
        if test_app in settings.INSTALLED_APPS:
            try:
                test_frame = import_string(module_or_class_name)
            except ImportError:
                # import_string() can raise ImportError if a submodule's parent
                # module hasn't already been imported during test discovery.
                # This can happen in at least two cases:
                # 1. When running a subset of tests in a module, the test
                #    runner won't import tests in that module's other
                #    submodules.
                # 2. When the parallel test runner spawns workers with an empty
                #    import cache.
                test_to_mark = import_string(test_name)
                test_frame = sys.modules.get(test_to_mark.__module__)
            else:
                test_to_mark = getattr(test_frame, name_to_mark)
            if skip_reason:
                setattr(test_frame, name_to_mark, skip(skip_reason)(test_to_mark))
            else:
                setattr(test_frame, name_to_mark, expectedFailure(test_to_mark))

    def sql_table_creation_suffix(self):
        """
        SQL to append to the end of the test table creation statements.
        """
        return ""

    def test_db_signature(self):

Review comment (refactor):
Now that we lost the other helper's docstring suggesting what a "frame" is, I'm hoping this is sort of self-explanatory if in the 1-helper version you see it's the thing having `setattr()` run on it. (?)

Code after:
        with self._nodb_cursor() as cursor:
            cursor.execute(
                "DROP DATABASE %s" % self.connection.ops.quote_name(test_database_name)
            )

    def mark_expected_failures_and_skips(self):
        """
        Mark tests in Django's test suite which are expected failures on this
        database and test which should be skipped on this database.
        """
        for test_name in self.connection.features.django_test_expected_failures:
            self._mark_test(test_name)
        for reason, tests in self.connection.features.django_test_skips.items():
            for test_name in tests:
                self._mark_test(test_name, reason)

    def _mark_test(self, test_name, skip_reason=None):
        # Only load unittest during testing.
        from unittest import expectedFailure, skip

        module_or_class_name, _, name_to_mark = test_name.rpartition(".")
        test_app = test_name.split(".")[0]
        # Importing a test app that isn't installed raises RuntimeError.
        if test_app in settings.INSTALLED_APPS:
            try:
                test_frame = import_string(module_or_class_name)
            except ImportError:
                # import_string() can raise ImportError if a submodule's parent
                # module hasn't already been imported during test discovery.
                # This can happen in at least two cases:
                # 1. When running a subset of tests in a module, the test
                #    runner won't import tests in that module's other
                #    submodules.
                # 2. When the parallel test runner spawns workers with an empty
                #    import cache.
                test_to_mark = import_string(test_name)
                test_frame = sys.modules.get(test_to_mark.__module__)
            else:
                test_to_mark = getattr(test_frame, name_to_mark)
            if skip_reason:
                setattr(test_frame, name_to_mark, skip(skip_reason)(test_to_mark))
            else:
                setattr(test_frame, name_to_mark, expectedFailure(test_to_mark))

    def sql_table_creation_suffix(self):
        """
        SQL to append to the end of the test table creation statements.
        """
        return ""

    def test_db_signature(self):