1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixes #2333 -- Added test fixtures framework.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4659 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2007-03-01 13:11:08 +00:00
parent f54777406d
commit f2582eb972
27 changed files with 887 additions and 86 deletions

View File

@@ -1,5 +1,7 @@
import re, doctest, unittest
from django.db import transaction
from django.core import management
from django.db.models import get_apps
normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s)
@@ -28,3 +30,21 @@ class DocTestRunner(doctest.DocTestRunner):
from django.db import transaction
transaction.rollback_unless_managed()
class TestCase(unittest.TestCase):
def install_fixtures(self):
"""If the Test Case class has a 'fixtures' member, clear the database and
install the named fixtures at the start of each test.
"""
management.flush(verbosity=0, interactive=False)
if hasattr(self, 'fixtures'):
management.load_data(self.fixtures, verbosity=0)
def run(self, result=None):
"""Wrapper around default run method so that user-defined Test Cases
automatically call install_fixtures without having to include a call to
super().
"""
self.install_fixtures()
super(TestCase, self).run(result)