          if model == current_model:
              model = None
  
          field = relation if direct else relation.field
          m2m = isinstance(field, related.ManyToManyField)
          return relation, model, direct, m2m
  
  
  class GetFieldsTests(OptionsBaseTests):
  
      def test_get_fields_is_immutable(self):
 
</s> remove             return isinstance(f, Field) and not isinstance(f, related.ManyToManyField)
 </s> add             return isinstance(f, Field) and not f.many_to_many </s> remove                             not isinstance(new_field, models.ManyToManyField)):
 </s> add                             not new_field.many_to_many): </s> remove                 both_m2m = (
                    isinstance(old_field, models.ManyToManyField) and
                    isinstance(new_field, models.ManyToManyField)
                )
                neither_m2m = (
                    not isinstance(old_field, models.ManyToManyField) and
                    not isinstance(new_field, models.ManyToManyField)
                )
 </s> add                 both_m2m = old_field.many_to_many and new_field.many_to_many
                neither_m2m = not old_field.many_to_many and not new_field.many_to_many </s> remove             "The value of 'filter_horizontal[0]' must be a ManyToManyField.",
 </s> add             "The value of 'filter_horizontal[0]' must be a many-to-many field.", </s> remove             "The value of 'filter_vertical[0]' must be a ManyToManyField.",
 </s> add             "The value of 'filter_vertical[0]' must be a many-to-many field.",
        return relation, model, direct, bool(field.many_to_many)  # many_to_many can be None
          if model == current_model:
              model = None
  
          field = relation if direct else relation.field
        return relation, model, direct, bool(field.many_to_many)  # many_to_many can be None
        return relation, model, direct, bool(field.many_to_many)  # many_to_many can be None
  
  
  class GetFieldsTests(OptionsBaseTests):
  
      def test_get_fields_is_immutable(self):
keep keep keep keep replace replace keep keep keep keep keep
 Refs #24227 -- Replaced M2M isinstance checks by field.many_to_many

Thanks Markus Holtermann, Collin Anderson and Tim Graham for the reviews. 
tests/model_meta/tests.py