Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x] Changed testing strategy used in 6b03179.

Avoid polluting the app cache as it causes unrelated test failures.

Refs #19688.

Backport of 7b49da1 from master.
  • Loading branch information...
commit 455baa68ebabb472f901e3b476b3344c94090303 1 parent f8b41da
Aymeric Augustin authored February 25, 2013
22  tests/modeltests/base/models.py
... ...
@@ -1,5 +1,23 @@
1  
-from django.db.models.base import ModelBase
  1
+from __future__ import unicode_literals
2 2
 
  3
+from django.db import models
  4
+from django.utils import six
3 5
 
4  
-class CustomBaseModel(ModelBase):
  6
+
  7
+# The models definitions below used to crash. Generating models dynamically
  8
+# at runtime is a bad idea because it pollutes the app cache. This doesn't
  9
+# integrate well with the test suite but at least it prevents regressions.
  10
+
  11
+
  12
+class CustomBaseModel(models.base.ModelBase):
5 13
     pass
  14
+
  15
+
  16
+class MyModel(six.with_metaclass(CustomBaseModel, models.Model)):
  17
+        """Model subclass with a custom base using six.with_metaclass."""
  18
+
  19
+
  20
+if not six.PY3:
  21
+    class MyModel(models.Model):
  22
+        """Model subclass with a custom base using __metaclass__."""
  23
+        __metaclass__ = CustomBaseModel
36  tests/modeltests/base/tests.py
... ...
@@ -1,36 +0,0 @@
1  
-from __future__ import unicode_literals
2  
-
3  
-from django.db import models
4  
-from django.test.testcases import SimpleTestCase
5  
-from django.utils import six
6  
-from django.utils.unittest import skipIf
7  
-
8  
-from .models import CustomBaseModel
9  
-
10  
-
11  
-class CustomBaseTest(SimpleTestCase):
12  
-
13  
-    @skipIf(six.PY3, 'test metaclass definition under Python 2')
14  
-    def test_py2_custom_base(self):
15  
-        """
16  
-        Make sure models.Model can be subclassed with a valid custom base
17  
-        using __metaclass__
18  
-        """
19  
-        try:
20  
-            class MyModel(models.Model):
21  
-                __metaclass__ = CustomBaseModel
22  
-        except Exception:
23  
-            self.fail("models.Model couldn't be subclassed with a valid "
24  
-                      "custom base using __metaclass__.")
25  
-
26  
-    def test_six_custom_base(self):
27  
-        """
28  
-        Make sure models.Model can be subclassed with a valid custom base
29  
-        using `six.with_metaclass`.
30  
-        """
31  
-        try:
32  
-            class MyModel(six.with_metaclass(CustomBaseModel, models.Model)):
33  
-                pass
34  
-        except Exception:
35  
-            self.fail("models.Model couldn't be subclassed with a valid "
36  
-                      "custom base using `six.with_metaclass`.")

0 notes on commit 455baa6

Please sign in to comment.
Something went wrong with that request. Please try again.