Benjamin Peterson | bed7d04 | 2009-07-19 21:01:52 +0000 | [diff] [blame] | 1 | """ |
| 2 | Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's |
| 3 | Smalltalk testing framework. |
| 4 | |
| 5 | This module contains the core framework classes that form the basis of |
| 6 | specific test cases and suites (TestCase, TestSuite etc.), and also a |
| 7 | text-based utility class for running the tests and reporting the results |
| 8 | (TextTestRunner). |
| 9 | |
| 10 | Simple usage: |
| 11 | |
| 12 | import unittest |
| 13 | |
| 14 | class IntegerArithmenticTestCase(unittest.TestCase): |
| 15 | def testAdd(self): ## test method names begin 'test*' |
| 16 | self.assertEqual((1 + 2), 3) |
| 17 | self.assertEqual(0 + 1, 1) |
| 18 | def testMultiply(self): |
| 19 | self.assertEqual((0 * 10), 0) |
| 20 | self.assertEqual((5 * 8), 40) |
| 21 | |
| 22 | if __name__ == '__main__': |
| 23 | unittest.main() |
| 24 | |
| 25 | Further information is available in the bundled documentation, and from |
| 26 | |
| 27 | http://docs.python.org/library/unittest.html |
| 28 | |
| 29 | Copyright (c) 1999-2003 Steve Purcell |
Benjamin Peterson | 46a9900 | 2010-01-09 18:45:30 +0000 | [diff] [blame] | 30 | Copyright (c) 2003-2010 Python Software Foundation |
Benjamin Peterson | bed7d04 | 2009-07-19 21:01:52 +0000 | [diff] [blame] | 31 | This module is free software, and you may redistribute it and/or modify |
| 32 | it under the same terms as Python itself, so long as this copyright message |
| 33 | and disclaimer are retained in their original form. |
| 34 | |
| 35 | IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, |
| 36 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF |
| 37 | THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 38 | DAMAGE. |
| 39 | |
| 40 | THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT |
| 41 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 42 | PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, |
| 43 | AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 44 | SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 45 | """ |
| 46 | |
| 47 | __all__ = ['TestResult', 'TestCase', 'TestSuite', |
| 48 | 'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main', |
| 49 | 'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless', |
Michael Foord | 65b69a1 | 2010-03-27 13:25:41 +0000 | [diff] [blame] | 50 | 'expectedFailure', 'TextTestResult', 'installHandler', |
Michael Foord | de4ceab | 2010-04-25 19:53:49 +0000 | [diff] [blame] | 51 | 'registerResult', 'removeResult', 'removeHandler'] |
Benjamin Peterson | bed7d04 | 2009-07-19 21:01:52 +0000 | [diff] [blame] | 52 | |
| 53 | # Expose obsolete functions for backwards compatibility |
| 54 | __all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases']) |
| 55 | |
Benjamin Peterson | eab4b4c | 2010-03-22 02:53:52 +0000 | [diff] [blame] | 56 | __unittest = True |
Benjamin Peterson | bed7d04 | 2009-07-19 21:01:52 +0000 | [diff] [blame] | 57 | |
| 58 | from .result import TestResult |
| 59 | from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf, |
| 60 | skipUnless, expectedFailure) |
Benjamin Peterson | 847a411 | 2010-03-14 15:04:17 +0000 | [diff] [blame] | 61 | from .suite import BaseTestSuite, TestSuite |
Benjamin Peterson | bed7d04 | 2009-07-19 21:01:52 +0000 | [diff] [blame] | 62 | from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames, |
| 63 | findTestCases) |
| 64 | from .main import TestProgram, main |
Michael Foord | 34c9462 | 2010-02-10 15:51:42 +0000 | [diff] [blame] | 65 | from .runner import TextTestRunner, TextTestResult |
Michael Foord | de4ceab | 2010-04-25 19:53:49 +0000 | [diff] [blame] | 66 | from .signals import installHandler, registerResult, removeResult, removeHandler |
Michael Foord | 34c9462 | 2010-02-10 15:51:42 +0000 | [diff] [blame] | 67 | |
| 68 | # deprecated |
| 69 | _TextTestResult = TextTestResult |