summaryrefslogtreecommitdiff
path: root/tests/get_or_create/tests.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-12-21 21:19:05 +0100
committerClaude Paroz <claude@2xlibre.net>2014-12-30 18:16:25 +0100
commit51890ce8898f821d28f2f6fb6071c936e9bd88f0 (patch)
tree6522c597d411086b0a5c2ec3dd7a1d9bc2feeafd /tests/get_or_create/tests.py
parent66f9a74b4514bd259976ce8ee3a4e78288358a5f (diff)
Applied ignore_warnings to Django tests
Diffstat (limited to 'tests/get_or_create/tests.py')
-rw-r--r--tests/get_or_create/tests.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/tests/get_or_create/tests.py b/tests/get_or_create/tests.py
index 33ac1317a5..f15d84323d 100644
--- a/tests/get_or_create/tests.py
+++ b/tests/get_or_create/tests.py
@@ -2,11 +2,10 @@ from __future__ import unicode_literals
from datetime import date
import traceback
-import warnings
from django.db import IntegrityError, DatabaseError
from django.utils.encoding import DjangoUnicodeDecodeError
-from django.test import TestCase, TransactionTestCase
+from django.test import TestCase, TransactionTestCase, ignore_warnings
from .models import (DefaultPerson, Person, ManualPrimaryKeyTest, Profile,
Tag, Thing, Publisher, Author, Book)
@@ -155,18 +154,17 @@ class GetOrCreateTestsWithManualPKs(TestCase):
formatted_traceback = traceback.format_exc()
self.assertIn(str('obj.save'), formatted_traceback)
+ # MySQL emits a warning when broken data is saved
+ @ignore_warnings(module='django.db.backends.mysql.base')
def test_savepoint_rollback(self):
"""
Regression test for #20463: the database connection should still be
usable after a DataError or ProgrammingError in .get_or_create().
"""
try:
- # Hide warnings when broken data is saved with a warning (MySQL).
- with warnings.catch_warnings():
- warnings.simplefilter('ignore')
- Person.objects.get_or_create(
- birthday=date(1970, 1, 1),
- defaults={'first_name': b"\xff", 'last_name': b"\xff"})
+ Person.objects.get_or_create(
+ birthday=date(1970, 1, 1),
+ defaults={'first_name': b"\xff", 'last_name': b"\xff"})
except (DatabaseError, DjangoUnicodeDecodeError):
Person.objects.create(
first_name="Bob", last_name="Ross", birthday=date(1950, 1, 1))