Changeset 5729
- Timestamp:
- 07/20/07 08:57:49 (1 year ago)
- Files:
-
- django/trunk/django/test/simple.py (modified) (2 diffs)
- django/trunk/docs/testing.txt (modified) (2 diffs)
- django/trunk/tests/modeltests/test_client/tests.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/test/simple.py
r5391 r5729 15 15 suite = unittest.TestSuite() 16 16 17 # Load unit and doctests in the models.py file 18 suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(app_module)) 19 try: 20 suite.addTest(doctest.DocTestSuite(app_module, 21 checker=doctestOutputChecker, 22 runner=DocTestRunner)) 23 except ValueError: 24 # No doc tests in models.py 25 pass 17 # Load unit and doctests in the models.py module. If module has 18 # a suite() method, use it. Otherwise build the test suite ourselves. 19 if hasattr(app_module, 'suite'): 20 suite.addTest(app_module.suite()) 21 else: 22 suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(app_module)) 23 try: 24 suite.addTest(doctest.DocTestSuite(app_module, 25 checker=doctestOutputChecker, 26 runner=DocTestRunner)) 27 except ValueError: 28 # No doc tests in models.py 29 pass 26 30 27 31 # Check to see if a separate 'tests' module exists parallel to the … … 31 35 test_module = __import__('.'.join(app_path + [TEST_MODULE]), {}, {}, TEST_MODULE) 32 36 33 suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module)) 34 try: 35 suite.addTest(doctest.DocTestSuite(test_module, 36 checker=doctestOutputChecker, 37 runner=DocTestRunner)) 38 except ValueError: 39 # No doc tests in tests.py 40 pass 37 # Load unit and doctests in the tests.py module. If module has 38 # a suite() method, use it. Otherwise build the test suite ourselves. 39 if hasattr(test_module, 'suite'): 40 suite.addTest(test_module.suite()) 41 else: 42 suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module)) 43 try: 44 suite.addTest(doctest.DocTestSuite(test_module, 45 checker=doctestOutputChecker, 46 runner=DocTestRunner)) 47 except ValueError: 48 # No doc tests in tests.py 49 pass 41 50 except ImportError, e: 42 51 # Couldn't import tests.py. Was it due to a missing file, or django/trunk/docs/testing.txt
r5702 r5729 119 119 self.assertEquals(self.cat.speak(), 'The cat says "meow"') 120 120 121 When you `run your tests`_, the test utility will find all the test cases 122 (that is, subclasses of ``unittest.TestCase``) in ``models.py`` and 123 ``tests.py``, automatically build a test suite out of those test cases, 124 and run that suite. 121 When you `run your tests`_, the default behavior of the test utility is 122 to find all the test cases (that is, subclasses of ``unittest.TestCase``) 123 in ``models.py`` and ``tests.py``, automatically build a test suite out of 124 those test cases, and run that suite. 125 126 However, if you define a method called ``suite()`` in either ``models.py`` or 127 ``tests.py``, that method will be used to construct the test suite for that 128 module. This follows the `suggested organization`_ for unit tests. See the 129 Python documentation for more details on how to construct a complex test 130 suite. 125 131 126 132 For more details about ``unittest``, see the `standard library unittest … … 130 136 .. _standard library unittest documentation: unittest_ 131 137 .. _run your tests: `Running tests`_ 138 .. _suggested organization: http://docs.python.org/lib/organizing-tests.html 132 139 133 140 Which should I use?
