Skip to content

Commit 8065651

Browse files
committed
print sql errors
1 parent 2645526 commit 8065651

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,4 @@ jobs:
409409
poetry run pip install -U "${{ matrix.django-version }}"
410410
- name: Run Full Unit Tests
411411
run: |
412-
poetry run pytest
412+
poetry run pytest -s

django_enum/tests/tests.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from django_enum.utils import choices, get_set_bits, labels, names, values
4949
from django_test_migrations.constants import MIGRATION_TEST_MARKER
5050
from django_test_migrations.contrib.unittest_case import MigratorTestCase
51+
from django.test.utils import CaptureQueriesContext
5152

5253
try:
5354
import django_filters
@@ -944,13 +945,16 @@ def test_max_length_override(self):
944945

945946
def test_serialization(self):
946947
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-
raise
948+
from django.db import connection
949+
950+
with CaptureQueriesContext(connection) as ctx:
951+
try:
952+
# code that runs SQL queries
953+
tester = self.MODEL_CLASS.objects.create(**self.values_params)
954+
except DatabaseError:
955+
from pprint import pprint
956+
pprint(ctx.captured_queries)
957+
raise
954958

955959
serialized = serializers.serialize('json', self.MODEL_CLASS.objects.all())
956960

0 commit comments

Comments
 (0)