Code

Ticket #5624: 0001-Add-pre_test-signal.patch

File 0001-Add-pre_test-signal.patch, 2.6 KB (added by eikke@…, 7 years ago)

Add pre_test signal

  • django/db/models/signals.py

    From c28b1ad64e691453a404a399926be1d2d3e8d105 Mon Sep 17 00:00:00 2001
    From: Nicolas Trangez <ikke@nicolast.be>
    Date: Thu, 27 Sep 2007 13:57:50 +0200
    Subject: [PATCH] Add pre_test signal
    
    Added a new signal, pre_test, which is sent when running a project testsuite.
    The signal is sent after test database creation, before actually running the
    tests.
    
    It can eg. be used to load some test data fixture to prepopulate the test
    database, when connecting to it in some application's management.py file.
    ---
     django/db/models/signals.py |    2 ++
     django/test/simple.py       |    4 +++-
     django/test/utils.py        |    6 ++++++
     3 files changed, 11 insertions(+), 1 deletions(-)
    
    diff --git a/django/db/models/signals.py b/django/db/models/signals.py
    index 2171cb1..a8d2090 100644
    a b pre_delete = object() 
    1010post_delete = object() 
    1111 
    1212post_syncdb = object() 
     13 
     14pre_test = object() 
  • django/test/simple.py

    diff --git a/django/test/simple.py b/django/test/simple.py
    index 6fa381a..c8668e5 100644
    a b from 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 
    66from django.test.utils import create_test_db, destroy_test_db 
     7from django.test.utils import emit_pre_test_signal 
    78from django.test.testcases import OutputChecker, DocTestRunner 
    89 
    910# The module name for tests outside models.py 
    def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): 
    140141 
    141142    old_name = settings.DATABASE_NAME 
    142143    create_test_db(verbosity, autoclobber=not interactive) 
     144    emit_pre_test_signal(verbosity, interactive) 
    143145    result = unittest.TextTestRunner(verbosity=verbosity).run(suite) 
    144146    destroy_test_db(old_name, verbosity) 
    145147     
    146148    teardown_test_environment() 
    147149     
    148150    return len(result.failures) + len(result.errors) 
    149      
    150  No newline at end of file 
     151     
  • django/test/utils.py

    diff --git a/django/test/utils.py b/django/test/utils.py
    index 6edd186..5d20983 100644
    a b def destroy_test_db(old_database_name, verbosity=1): 
    184184        time.sleep(1) # To avoid "database is being accessed by other users" errors. 
    185185        cursor.execute("DROP DATABASE %s" % connection.ops.quote_name(TEST_DATABASE_NAME)) 
    186186        connection.close() 
     187 
     188def emit_pre_test_signal(verbosity, interactive): 
     189    from django.db import models 
     190    from django.dispatch import dispatcher 
     191    dispatcher.send(signal=models.signals.pre_test, verbosity=verbosity, 
     192        interactive=interactive)