Ticket #11627: test_suite.1.diff

File test_suite.1.diff, 2.4 KB (added by Filip Gruszczyński, 15 years ago)

Early version of using test suites in tests

  • django/test/simple.py

     
    4444    if hasattr(app_module, 'suite'):
    4545        suite.addTest(app_module.suite())
    4646    else:
    47         suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(app_module))
     47        suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(app_module))                       
    4848        try:
    4949            suite.addTest(doctest.DocTestSuite(app_module,
    5050                                               checker=doctestOutputChecker,
     
    8282    if len(parts) < 2 or len(parts) > 3:
    8383        raise ValueError("Test label '%s' should be of the form app.TestCase or app.TestCase.test_method" % label)
    8484
    85     app_module = get_app(parts[0])
    86     TestClass = getattr(app_module, parts[1], None)
     85    module = get_app(parts[0])
     86    TestClass = getattr(module, parts[1], None)
    8787
    8888    # Couldn't find the test class in models.py; look in tests.py
    8989    if TestClass is None:
    90         test_module = get_tests(app_module)
    91         if test_module:
    92             TestClass = getattr(test_module, parts[1], None)
     90        module = get_tests(module)
     91        if module:
     92            TestClass = getattr(module, parts[1], None)
    9393
    9494    if len(parts) == 2: # label is app.TestClass
    9595        try:
    96             return unittest.TestLoader().loadTestsFromTestCase(TestClass)
     96            # retrieves tests from either a TestCase or TestSuite
     97            return unittest.TestLoader().loadTestsFromName(parts[1], module)
    9798        except TypeError:
    9899            raise ValueError("Test label '%s' does not refer to a test class" % label)
    99100    else: # label is app.TestClass.test_method
  • django/test/testcases.py

     
    460460        transaction.rollback()
    461461        transaction.leave_transaction_management()
    462462        connection.close()
     463
     464class TestSuite(unittest.TestSuite):
     465        pass
  • django/test/__init__.py

     
    33"""
    44
    55from django.test.client import Client
    6 from django.test.testcases import TestCase, TransactionTestCase
     6from django.test.testcases import TestCase, TransactionTestCase, TestSuite
Back to Top