summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-02-25 00:09:13 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-02-25 00:11:10 +0100
commit455baa68ebabb472f901e3b476b3344c94090303 (patch)
tree00eabb9bfd0a1c85551bec58c216ebd25fe3e227
parentf8b41da43156aa4283c83f2e579e8b18157c9b20 (diff)
[1.5.x] Changed testing strategy used in 6b03179e.
Avoid polluting the app cache as it causes unrelated test failures. Refs #19688. Backport of 7b49da1 from master.
-rw-r--r--tests/modeltests/base/models.py22
-rw-r--r--tests/modeltests/base/tests.py36
2 files changed, 20 insertions, 38 deletions
diff --git a/tests/modeltests/base/models.py b/tests/modeltests/base/models.py
index 3d39302aba..bddb406820 100644
--- a/tests/modeltests/base/models.py
+++ b/tests/modeltests/base/models.py
@@ -1,5 +1,23 @@
-from django.db.models.base import ModelBase
+from __future__ import unicode_literals
+from django.db import models
+from django.utils import six
-class CustomBaseModel(ModelBase):
+
+# The models definitions below used to crash. Generating models dynamically
+# at runtime is a bad idea because it pollutes the app cache. This doesn't
+# integrate well with the test suite but at least it prevents regressions.
+
+
+class CustomBaseModel(models.base.ModelBase):
pass
+
+
+class MyModel(six.with_metaclass(CustomBaseModel, models.Model)):
+ """Model subclass with a custom base using six.with_metaclass."""
+
+
+if not six.PY3:
+ class MyModel(models.Model):
+ """Model subclass with a custom base using __metaclass__."""
+ __metaclass__ = CustomBaseModel
diff --git a/tests/modeltests/base/tests.py b/tests/modeltests/base/tests.py
deleted file mode 100644
index 6229b7a305..0000000000
--- a/tests/modeltests/base/tests.py
+++ /dev/null
@@ -1,36 +0,0 @@
-from __future__ import unicode_literals
-
-from django.db import models
-from django.test.testcases import SimpleTestCase
-from django.utils import six
-from django.utils.unittest import skipIf
-
-from .models import CustomBaseModel
-
-
-class CustomBaseTest(SimpleTestCase):
-
- @skipIf(six.PY3, 'test metaclass definition under Python 2')
- def test_py2_custom_base(self):
- """
- Make sure models.Model can be subclassed with a valid custom base
- using __metaclass__
- """
- try:
- class MyModel(models.Model):
- __metaclass__ = CustomBaseModel
- except Exception:
- self.fail("models.Model couldn't be subclassed with a valid "
- "custom base using __metaclass__.")
-
- def test_six_custom_base(self):
- """
- Make sure models.Model can be subclassed with a valid custom base
- using `six.with_metaclass`.
- """
- try:
- class MyModel(six.with_metaclass(CustomBaseModel, models.Model)):
- pass
- except Exception:
- self.fail("models.Model couldn't be subclassed with a valid "
- "custom base using `six.with_metaclass`.")