Skip to content

Commit 9e6896b

Browse files
committed
print SQL on error in tests
1 parent 8e3b453 commit 9e6896b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

django_enum/tests/benchmarks.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from django.db import connection
1010
from django.db.models import Q
11-
from django.test import TestCase, override_settings
11+
from django.test import TestCase, modify_settings
1212
from django_enum.tests.benchmark import enums as benchmark_enums
1313
from django_enum.tests.benchmark import models as benchmark_models
1414

@@ -63,6 +63,8 @@ def create(self, obj=None):
6363
SingleNoCoercePerf,
6464
)
6565

66+
67+
@modify_settings(DEBUG=False)
6668
class PerformanceTest(BulkCreateMixin, TestCase):
6769
"""
6870
We intentionally test bulk operations performance because thats what
@@ -278,6 +280,19 @@ def test_single_field_benchmark(self):
278280
self.assertTrue((no_coerce_time / choice_time) < 2)
279281

280282

283+
@modify_settings(
284+
DEBUG=False,
285+
INSTALLED_APPS = [
286+
'django_enum.tests.benchmark',
287+
'django.contrib.auth',
288+
'django.contrib.contenttypes',
289+
'django.contrib.sessions',
290+
'django.contrib.sites',
291+
'django.contrib.messages',
292+
'django.contrib.staticfiles',
293+
'django.contrib.admin',
294+
]
295+
)
281296
class FlagBenchmarks(BulkCreateMixin, TestCase):
282297

283298
COUNT = 10000

django_enum/tests/tests.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,14 @@ def test_max_length_override(self):
943943
# print(len(obj.non_strict_text))
944944

945945
def test_serialization(self):
946-
tester = self.MODEL_CLASS.objects.create(**self.values_params)
947-
from django.core.serializers import json
946+
from django.db.utils import DatabaseError
947+
try:
948+
tester = self.MODEL_CLASS.objects.create(**self.values_params)
949+
except DatabaseError:
950+
from django.db import connection
951+
from pprint import pprint
952+
pprint(connection.queries)
953+
948954
serialized = serializers.serialize('json', self.MODEL_CLASS.objects.all())
949955

950956
tester.delete()

0 commit comments

Comments
 (0)