Ticket #5608: 0001-Implement-TEST_FIXTURES-feature.patch

File 0001-Implement-TEST_FIXTURES-feature.patch, 3.3 KB (added by eikke@…, 17 years ago)

Implement TEST_FIXTURES functionality

  • django/conf/global_settings.py

    From c80b80f3aeaeedbc91d44c3db17dc631ae8a919e Mon Sep 17 00:00:00 2001
    From: Nicolas Trangez <ikke@nicolast.be>
    Date: Wed, 26 Sep 2007 13:35:57 +0200
    Subject: [PATCH] Implement TEST_FIXTURES feature
    
    Setting TEST_FIXTURES to a tuple listing some fixture names will
    auto-load these fixtures in the test database before running any
    tests. This is especially useful when using doctests, which don't
    allow to define a fixture to load, unlike unittests.
    ---
     django/conf/global_settings.py |    4 ++++
     django/test/simple.py          |    4 ++--
     django/test/utils.py           |    7 +++++++
     docs/settings.txt              |   10 ++++++++++
     4 files changed, 23 insertions(+), 2 deletions(-)
    
    diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
    index b3cbf09..8e7df95 100644
    a b TEST_DATABASE_NAME = None  
    350350TEST_DATABASE_CHARSET = None
    351351TEST_DATABASE_COLLATION = None
    352352
     353# The name of a fixture to load in the test database before
     354# running tests
     355TEST_FIXTURES = None
     356
    353357############
    354358# FIXTURES #
    355359############
  • django/test/simple.py

    diff --git a/django/test/simple.py b/django/test/simple.py
    index 6fa381a..5d26278 100644
    a b from django.conf import settings  
    33from django.db.models import get_app, get_apps
    44from django.test import _doctest as doctest
    55from django.test.utils import setup_test_environment, teardown_test_environment
    6 from django.test.utils import create_test_db, destroy_test_db
     6from django.test.utils import create_test_db, populate_test_db, destroy_test_db
    77from django.test.testcases import OutputChecker, DocTestRunner
    88
    99# The module name for tests outside models.py
    def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):  
    140140
    141141    old_name = settings.DATABASE_NAME
    142142    create_test_db(verbosity, autoclobber=not interactive)
     143    populate_test_db(settings.TEST_FIXTURES)
    143144    result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
    144145    destroy_test_db(old_name, verbosity)
    145146   
    146147    teardown_test_environment()
    147148   
    148149    return len(result.failures) + len(result.errors)
    149    
    150  No newline at end of file
  • django/test/utils.py

    diff --git a/django/test/utils.py b/django/test/utils.py
    index 6edd186..4a19f81 100644
    a b def create_test_db(verbosity=1, autoclobber=False):  
    161161
    162162    return TEST_DATABASE_NAME
    163163
     164def populate_test_db(fixtures):
     165    if not fixtures:
     166        return
     167
     168    # Load test fixture in DB
     169    call_command('loaddata', *fixtures, **{'verbosity': 0})
     170
    164171def destroy_test_db(old_database_name, verbosity=1):
    165172    # If the database wants to drop the test DB itself, let it
    166173    creation_module = get_creation_module()
  • docs/settings.txt

    diff --git a/docs/settings.txt b/docs/settings.txt
    index 7ad1f64..af6c906 100644
    a b of the MySQL manual for details).  
    910910
    911911.. _section 10.3.2: http://www.mysql.org/doc/refman/5.0/en/charset-database.html
    912912
     913TEST_FIXTURES
     914-------------
     915
     916**New in Django development version **
     917
     918Default: ``None``
     919
     920The fixtures to load in the test database before running any tests. This is a
     921tuple giving the name of all fixtures to load.
     922
    913923TEST_DATABASE_NAME
    914924------------------
    915925
Back to Top