Ticket #14319: new_test_signals_patch.diff

File new_test_signals_patch.diff, 3.8 KB (added by Jim Dalton, 14 years ago)

Patch to add test_setup and test_teardown signals to Django test framework

  • django/test/simple.py

     
    77from django.test import _doctest as doctest
    88from django.test.utils import setup_test_environment, teardown_test_environment
    99from django.test.testcases import OutputChecker, DocTestRunner, TestCase
     10from django.test.signals import test_setup, test_teardown
    1011
    1112# The module name for tests outside models.py
    1213TEST_MODULE = 'tests'
     
    230231        self.failfast = failfast
    231232
    232233    def setup_test_environment(self, **kwargs):
    233         setup_test_environment()
     234        test_setup.send(sender=self)
    234235        settings.DEBUG = False
    235236
    236237    def build_suite(self, test_labels, extra_tests=None, **kwargs):
     
    284285            connection.creation.destroy_test_db(old_name, self.verbosity)
    285286
    286287    def teardown_test_environment(self, **kwargs):
    287         teardown_test_environment()
     288        test_teardown.send(sender=self)
    288289
    289290    def suite_result(self, suite, result, **kwargs):
    290291        return len(result.failures) + len(result.errors)
     
    308309
    309310        Returns the number of tests that failed.
    310311        """
     312        suite = self.build_suite(test_labels, extra_tests)
    311313        self.setup_test_environment()
    312         suite = self.build_suite(test_labels, extra_tests)
    313314        old_config = self.setup_databases()
    314315        result = self.run_suite(suite)
    315316        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

     
    5252    return self.nodelist.render(context)
    5353
    5454
    55 def setup_test_environment():
     55def setup_test_environment(**kwargs):
    5656    """Perform any global pre-test setup. This involves:
    5757
    5858        - Installing the instrumented test renderer
     
    7171    mail.outbox = []
    7272
    7373    deactivate()
     74signals.test_setup.connect(setup_test_environment)
    7475
    75 def teardown_test_environment():
     76def teardown_test_environment(**kwargs):
    7677    """Perform any global post-test teardown. This involves:
    7778
    7879        - Restoring the original test renderer
     
    8990    del mail.original_email_backend
    9091
    9192    del mail.outbox
     93signals.test_teardown.connect(teardown_test_environment)
    9294
    9395def get_runner(settings):
    9496    test_path = settings.TEST_RUNNER.split('.')
  • docs/ref/signals.txt

     
    455455        The :class:`~django.template.Context` with which the template was
    456456        rendered.
    457457
     458test_setup
     459----------
     460
     461.. data:: django.test.signals.test_setup
     462   :module:
     463
     464.. versionadded:: 1.3
     465
     466Sent during global pre-test setup, just after applications have loaded and
     467the test suite has been built. This signal is not emitted during normal
     468operation.
     469
     470Arguments sent with this signal:
     471
     472    sender
     473        The :class:`~django.test.simple.DjangoTestSuiteRunner` object.
     474
     475test_teardown
     476-------------
     477
     478.. data:: django.test.signals.test_teardown
     479   :module:
     480
     481.. versionadded:: 1.3
     482
     483Sent during global post-test breakdown. This signal is not emitted during
     484normal operation.
     485
     486Arguments sent with this signal:
     487
     488    sender
     489        The :class:`~django.test.simple.DjangoTestSuiteRunner` object.
     490
    458491Database Wrappers
    459492=================
    460493
Back to Top