Moved IgnorePendingDeprecationWarningsMixin in django.test.utils.
This mixin is useful whenever deprecating a large part of Django.
This commit is contained in:
parent
63a9555d57
commit
3634948c88
|
@ -1,4 +1,5 @@
|
|||
import re
|
||||
import sys
|
||||
import warnings
|
||||
from functools import wraps
|
||||
from xml.dom.minidom import parseString, Node
|
||||
|
@ -380,3 +381,23 @@ class CaptureQueriesContext(object):
|
|||
if exc_type is not None:
|
||||
return
|
||||
self.final_queries = len(self.connection.queries)
|
||||
|
||||
|
||||
class IgnoreDeprecationWarningsMixin(object):
|
||||
|
||||
warning_class = DeprecationWarning
|
||||
|
||||
def setUp(self):
|
||||
super(IgnoreDeprecationWarningsMixin, self).setUp()
|
||||
self.catch_warnings = warnings.catch_warnings()
|
||||
self.catch_warnings.__enter__()
|
||||
warnings.filterwarnings("ignore", category=self.warning_class)
|
||||
|
||||
def tearDown(self):
|
||||
self.catch_warnings.__exit__(*sys.exc_info())
|
||||
super(IgnoreDeprecationWarningsMixin, self).tearDown()
|
||||
|
||||
|
||||
class IgnorePendingDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin):
|
||||
|
||||
warning_class = PendingDeprecationWarning
|
||||
|
|
|
@ -18,14 +18,12 @@ from django.middleware.http import ConditionalGetMiddleware
|
|||
from django.middleware.gzip import GZipMiddleware
|
||||
from django.middleware.transaction import TransactionMiddleware
|
||||
from django.test import TransactionTestCase, TestCase, RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
from django.test.utils import override_settings, IgnorePendingDeprecationWarningsMixin
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.six.moves import xrange
|
||||
from django.utils.unittest import expectedFailure, skipIf
|
||||
|
||||
from transactions.tests import IgnorePendingDeprecationWarningsMixin
|
||||
|
||||
from .models import Band
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import warnings
|
|||
|
||||
from django.db import connection, transaction, IntegrityError
|
||||
from django.test import TransactionTestCase, skipUnlessDBFeature
|
||||
from django.test.utils import IgnorePendingDeprecationWarningsMixin
|
||||
from django.utils import six
|
||||
from django.utils.unittest import skipIf, skipUnless
|
||||
|
||||
|
@ -319,19 +320,6 @@ class AtomicMiscTests(TransactionTestCase):
|
|||
transaction.atomic(Callable())
|
||||
|
||||
|
||||
class IgnorePendingDeprecationWarningsMixin(object):
|
||||
|
||||
def setUp(self):
|
||||
super(IgnorePendingDeprecationWarningsMixin, self).setUp()
|
||||
self.catch_warnings = warnings.catch_warnings()
|
||||
self.catch_warnings.__enter__()
|
||||
warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
|
||||
|
||||
def tearDown(self):
|
||||
self.catch_warnings.__exit__(*sys.exc_info())
|
||||
super(IgnorePendingDeprecationWarningsMixin, self).tearDown()
|
||||
|
||||
|
||||
class TransactionTests(IgnorePendingDeprecationWarningsMixin, TransactionTestCase):
|
||||
|
||||
def create_a_reporter_then_fail(self, first, last):
|
||||
|
|
|
@ -4,11 +4,9 @@ from django.db import (connection, connections, transaction, DEFAULT_DB_ALIAS, D
|
|||
IntegrityError)
|
||||
from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError
|
||||
from django.test import TransactionTestCase, skipUnlessDBFeature
|
||||
from django.test.utils import override_settings
|
||||
from django.test.utils import override_settings, IgnorePendingDeprecationWarningsMixin
|
||||
from django.utils.unittest import skipIf, skipUnless
|
||||
|
||||
from transactions.tests import IgnorePendingDeprecationWarningsMixin
|
||||
|
||||
from .models import Mod, M2mA, M2mB, SubMod
|
||||
|
||||
class ModelInheritanceTests(TransactionTestCase):
|
||||
|
|
Loading…
Reference in New Issue