blob: c55d563e0c38eb77db5a96eb357d3cd661ed1006 [file] [log] [blame]
Benjamin Petersonbed7d042009-07-19 21:01:52 +00001"""
2Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's
Brett Cannon07b954d2016-01-15 09:53:51 -08003Smalltalk testing framework (used with permission).
Benjamin Petersonbed7d042009-07-19 21:01:52 +00004
5This module contains the core framework classes that form the basis of
6specific test cases and suites (TestCase, TestSuite etc.), and also a
7text-based utility class for running the tests and reporting the results
8 (TextTestRunner).
9
10Simple usage:
11
12 import unittest
13
Mark Dickinson51ef0742013-09-09 10:34:24 +010014 class IntegerArithmeticTestCase(unittest.TestCase):
Berker Peksagaa5c2fd2016-09-28 17:28:41 +030015 def testAdd(self): # test method names begin with 'test'
Benjamin Petersonbed7d042009-07-19 21:01:52 +000016 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
25Further information is available in the bundled documentation, and from
26
27 http://docs.python.org/library/unittest.html
28
29Copyright (c) 1999-2003 Steve Purcell
Benjamin Peterson46a99002010-01-09 18:45:30 +000030Copyright (c) 2003-2010 Python Software Foundation
Benjamin Petersonbed7d042009-07-19 21:01:52 +000031This module is free software, and you may redistribute it and/or modify
32it under the same terms as Python itself, so long as this copyright message
33and disclaimer are retained in their original form.
34
35IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
36SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
37THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
38DAMAGE.
39
40THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
41LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
42PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
43AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
44SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
45"""
46
47__all__ = ['TestResult', 'TestCase', 'TestSuite',
48 'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main',
49 'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless',
Michael Foord65b69a12010-03-27 13:25:41 +000050 'expectedFailure', 'TextTestResult', 'installHandler',
Michael Foordde4ceab2010-04-25 19:53:49 +000051 'registerResult', 'removeResult', 'removeHandler']
Benjamin Petersonbed7d042009-07-19 21:01:52 +000052
53# Expose obsolete functions for backwards compatibility
54__all__.extend(['getTestCaseNames', 'makeSuite', 'findTestCases'])
55
Benjamin Petersoneab4b4c2010-03-22 02:53:52 +000056__unittest = True
Benjamin Petersonbed7d042009-07-19 21:01:52 +000057
58from .result import TestResult
59from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
60 skipUnless, expectedFailure)
Benjamin Peterson847a4112010-03-14 15:04:17 +000061from .suite import BaseTestSuite, TestSuite
Benjamin Petersonbed7d042009-07-19 21:01:52 +000062from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,
63 findTestCases)
64from .main import TestProgram, main
Michael Foord34c94622010-02-10 15:51:42 +000065from .runner import TextTestRunner, TextTestResult
Michael Foordde4ceab2010-04-25 19:53:49 +000066from .signals import installHandler, registerResult, removeResult, removeHandler
Michael Foord34c94622010-02-10 15:51:42 +000067
68# deprecated
69_TextTestResult = TextTestResult
Robert Collinsbf2bda32014-11-05 03:09:01 +130070
71# There are no tests here, so don't try to run anything discovered from
72# introspecting the symbols (e.g. FunctionTestCase). Instead, all our
73# tests come from within unittest.test.
74def load_tests(loader, tests, pattern):
75 import os.path
76 # top level directory cached on loader instance
77 this_dir = os.path.dirname(__file__)
78 return loader.discover(start_dir=this_dir, pattern=pattern)