Ticket #14319: new_test_signals_patch_3.diff

File new_test_signals_patch_3.diff, 4.2 KB (added by Jim Dalton, 13 years ago)
  • docs/ref/signals.txt

     
    504504    The :class:`~django.template.Context` with which the template was
    505505    rendered.
    506506
     507test_setup
     508----------
     509
     510.. data:: django.test.signals.test_setup
     511   :module:
     512
     513.. versionadded:: 1.4
     514
     515Sent during global pre-test setup, just after applications have loaded and
     516the test suite has been built. This signal is not emitted during normal
     517operation.
     518
     519Arguments sent with this signal:
     520
     521    sender
     522        The :class:`~django.test.simple.DjangoTestSuiteRunner` object.
     523
     524test_teardown
     525-------------
     526
     527.. data:: django.test.signals.test_teardown
     528   :module:
     529
     530.. versionadded:: 1.4
     531
     532Sent during global post-test breakdown. This signal is not emitted during
     533normal operation.
     534
     535Arguments sent with this signal:
     536
     537    sender
     538        The :class:`~django.test.simple.DjangoTestSuiteRunner` object.
     539
    507540Database Wrappers
    508541=================
    509542
  • django/test/simple.py

     
    55from django.test import _doctest as doctest
    66from django.test.utils import setup_test_environment, teardown_test_environment
    77from django.test.testcases import OutputChecker, DocTestRunner, TestCase
     8from django.test.signals import test_setup, test_teardown
    89from django.utils import unittest
    910
    1011__all__ = ('DjangoTestRunner', 'DjangoTestSuiteRunner', 'run_tests')
     
    226227        self.failfast = failfast
    227228
    228229    def setup_test_environment(self, **kwargs):
    229         setup_test_environment()
     230        test_setup.send(sender=self)
    230231        settings.DEBUG = False
    231232        unittest.installHandler()
    232233
     
    324325
    325326    def teardown_test_environment(self, **kwargs):
    326327        unittest.removeHandler()
    327         teardown_test_environment()
     328        test_teardown.send(sender=self)
    328329
    329330    def suite_result(self, suite, result, **kwargs):
    330331        return len(result.failures) + len(result.errors)
     
    348349
    349350        Returns the number of tests that failed.
    350351        """
     352        suite = self.build_suite(test_labels, extra_tests)
    351353        self.setup_test_environment()
    352         suite = self.build_suite(test_labels, extra_tests)
    353354        old_config = self.setup_databases()
    354355        result = self.run_suite(suite)
    355356        self.teardown_databases(old_config)
  • django/test/signals.py

     
    33template_rendered = Signal(providing_args=["template", "context"])
    44
    55setting_changed = Signal(providing_args=["setting", "value"])
     6
     7test_setup = Signal()
     8test_teardown = Signal()
  • django/test/utils.py

     
    77from django.conf import settings, UserSettingsHolder
    88from django.core import mail
    99from django.core.mail.backends import locmem
    10 from django.test.signals import template_rendered, setting_changed
     10from django.test.signals import template_rendered, setting_changed, test_setup, test_teardown
    1111from django.template import Template, loader, TemplateDoesNotExist
    1212from django.template.loaders import cached
    1313from django.utils.translation import deactivate
     
    6666    return self.nodelist.render(context)
    6767
    6868
    69 def setup_test_environment():
     69def setup_test_environment(**kwargs):
    7070    """Perform any global pre-test setup. This involves:
    7171
    7272        - Installing the instrumented test renderer
     
    8282    mail.outbox = []
    8383
    8484    deactivate()
     85test_setup.connect(setup_test_environment)
    8586
    86 
    87 def teardown_test_environment():
     87def teardown_test_environment(**kwargs):
    8888    """Perform any global post-test teardown. This involves:
    8989
    9090        - Restoring the original test renderer
     
    9898    del mail.original_email_backend
    9999
    100100    del mail.outbox
     101test_teardown.connect(teardown_test_environment)
    101102
    102103
    103104def get_warnings_state():
Back to Top