Ticket #14319: new_test_signals_patch_2.diff

File new_test_signals_patch_2.diff, 3.7 KB (added by Adam Seering, 14 years ago)

Updated patch, applies against trunk as of r16181

  • docs/ref/signals.txt

     
    481481    The :class:`~django.template.Context` with which the template was
    482482    rendered.
    483483
     484test_setup
     485----------
     486
     487.. data:: django.test.signals.test_setup
     488   :module:
     489
     490.. versionadded:: 1.3
     491
     492Sent during global pre-test setup, just after applications have loaded and
     493the test suite has been built. This signal is not emitted during normal
     494operation.
     495
     496Arguments sent with this signal:
     497
     498    sender
     499        The :class:`~django.test.simple.DjangoTestSuiteRunner` object.
     500
     501test_teardown
     502-------------
     503
     504.. data:: django.test.signals.test_teardown
     505   :module:
     506
     507.. versionadded:: 1.3
     508
     509Sent during global post-test breakdown. This signal is not emitted during
     510normal operation.
     511
     512Arguments sent with this signal:
     513
     514    sender
     515        The :class:`~django.test.simple.DjangoTestSuiteRunner` object.
     516
    484517Database Wrappers
    485518=================
    486519
  • 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

     
    11from django.dispatch import Signal
    22
    33template_rendered = Signal(providing_args=["template", "context"])
     4test_setup = Signal()
     5test_teardown = Signal()
     6 No newline at end of file
  • django/test/utils.py

     
    6060    return self.nodelist.render(context)
    6161
    6262
    63 def setup_test_environment():
     63def setup_test_environment(**kwargs):
    6464    """Perform any global pre-test setup. This involves:
    6565
    6666        - Installing the instrumented test renderer
     
    7676    mail.outbox = []
    7777
    7878    deactivate()
     79signals.test_setup.connect(setup_test_environment)
    7980
    80 
    81 def teardown_test_environment():
     81def teardown_test_environment(**kwargs):
    8282    """Perform any global post-test teardown. This involves:
    8383
    8484        - Restoring the original test renderer
     
    9292    del mail.original_email_backend
    9393
    9494    del mail.outbox
     95signals.test_teardown.connect(teardown_test_environment)
    9596
    9697
    9798def get_warnings_state():
Back to Top