diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index c738cbb27e9..1f6baa70ff5 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1,7 +1,6 @@ import datetime import re from decimal import Decimal -from unittest import skipIf from django.core.exceptions import FieldError from django.db import connection @@ -1204,16 +1203,16 @@ class AggregateTestCase(TestCase): ]) @skipUnlessDBFeature('supports_subqueries_in_group_by') - @skipIf( - connection.vendor == 'mysql' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode, - 'GROUP BY optimization does not work properly when ONLY_FULL_GROUP_BY ' - 'mode is enabled on MySQL, see #31331.', - ) def test_aggregation_subquery_annotation_multivalued(self): """ Subquery annotations must be included in the GROUP BY if they use potentially multivalued relations (contain the LOOKUP_SEP). """ + if connection.vendor == 'mysql' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode: + self.skipTest( + 'GROUP BY optimization does not work properly when ' + 'ONLY_FULL_GROUP_BY mode is enabled on MySQL, see #31331.' + ) subquery_qs = Author.objects.filter( pk=OuterRef('pk'), book__name=OuterRef('book__name'), diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 3bf6a22bac0..3d00a02a114 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -1,6 +1,5 @@ import datetime from decimal import Decimal -from unittest import skipIf from django.core.exceptions import FieldDoesNotExist, FieldError from django.db import connection @@ -647,12 +646,12 @@ class NonAggregateAnnotationTestCase(TestCase): datetime.date(2008, 11, 3), ]) - @skipIf( - connection.vendor == 'mysql' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode, - 'GROUP BY optimization does not work properly when ONLY_FULL_GROUP_BY ' - 'mode is enabled on MySQL, see #31331.', - ) def test_annotation_aggregate_with_m2o(self): + if connection.vendor == 'mysql' and 'ONLY_FULL_GROUP_BY' in connection.sql_mode: + self.skipTest( + 'GROUP BY optimization does not work properly when ' + 'ONLY_FULL_GROUP_BY mode is enabled on MySQL, see #31331.' + ) qs = Author.objects.filter(age__lt=30).annotate( max_pages=Case( When(book_contact_set__isnull=True, then=Value(0)), diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 8e3b76d0437..d31a12e504f 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -2,7 +2,7 @@ import datetime import itertools import unittest from copy import copy -from unittest import mock, skipIf +from unittest import mock from django.core.management.color import no_style from django.db import ( @@ -710,13 +710,13 @@ class SchemaTests(TransactionTestCase): editor.alter_field(Foo, old_field, new_field, strict=True) Foo.objects.create() - @skipIf( - connection.vendor == 'mysql' and - connection.mysql_is_mariadb and - (10, 4, 3) < connection.mysql_version < (10, 5, 2), - 'https://jira.mariadb.org/browse/MDEV-19598', - ) def test_alter_not_unique_field_to_primary_key(self): + if ( + connection.vendor == 'mysql' and + connection.mysql_is_mariadb and + (10, 4, 3) < connection.mysql_version < (10, 5, 2) + ): + self.skipTest('https://jira.mariadb.org/browse/MDEV-19598') # Create the table. with connection.schema_editor() as editor: editor.create_model(Author) @@ -2950,17 +2950,17 @@ class SchemaTests(TransactionTestCase): editor.alter_field(Author, new_field, old_field, strict=True) self.assertEqual(self.get_constraints_for_column(Author, 'weight'), []) - @skipIf( - connection.vendor == 'mysql' and - connection.mysql_is_mariadb and - (10, 4, 12) < connection.mysql_version < (10, 5), - 'https://jira.mariadb.org/browse/MDEV-22775', - ) def test_alter_pk_with_self_referential_field(self): """ Changing the primary key field name of a model with a self-referential foreign key (#26384). """ + if ( + connection.vendor == 'mysql' and + connection.mysql_is_mariadb and + (10, 4, 12) < connection.mysql_version < (10, 5) + ): + self.skipTest('https://jira.mariadb.org/browse/MDEV-22775') with connection.schema_editor() as editor: editor.create_model(Node) old_field = Node._meta.get_field('node_id') diff --git a/tests/serializers/test_data.py b/tests/serializers/test_data.py index 323cb13e821..9fbdd256fe3 100644 --- a/tests/serializers/test_data.py +++ b/tests/serializers/test_data.py @@ -378,21 +378,20 @@ if connection.features.interprets_empty_strings_as_nulls: data[2]._meta.get_field('data').empty_strings_allowed and data[3] is None)] -# Regression test for #8651 -- a FK to an object with PK of 0 -# This won't work on MySQL without the NO_AUTO_VALUE_ON_ZERO SQL mode since it -# won't let you create an object with an autoincrement primary key of 0. -if connection.features.allows_auto_pk_0: - test_data.extend([ - (data_obj, 0, Anchor, "Anchor 0"), - (fk_obj, 465, FKData, 0), - ]) - class SerializerDataTests(TestCase): pass def serializerTest(self, format): + # FK to an object with PK of 0. This won't work on MySQL without the + # NO_AUTO_VALUE_ON_ZERO SQL mode since it won't let you create an object + # with an autoincrement primary key of 0. + if connection.features.allows_auto_pk_0: + test_data.extend([ + (data_obj, 0, Anchor, 'Anchor 0'), + (fk_obj, 465, FKData, 0), + ]) # Create all the objects defined in the test data objects = []