Compatibility layer to use unittest
under Python
2.7 or unittest2 under Python 2.6 without having to worry about which is
in use.
Attention
Please refer to Python’s unittest
documentation as the ultimate source of information, this is just a
compatibility layer.
TestLoader
[source]¶This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite
discover
(start_dir, pattern='test*.py', top_level_dir=None)[source]¶Find and return all test modules from the specified start directory, recursing into subdirectories to find them. Only test files that match the pattern will be loaded. (Using shell style pattern matching.)
All test modules must be importable from the top level of the project. If the start directory is not the top level directory then the top level directory must be specified separately.
If a test package name (directory with ‘__init__.py’) matches the pattern then the package will be checked for a ‘load_tests’ function. If this exists then it will be called with loader, tests, pattern.
If load_tests exists then discovery does not recurse into the package, load_tests is responsible for loading all tests in the package.
The pattern is deliberately not stored as a loader attribute so that packages can continue discovery themselves. top_level_dir is stored so load_tests does not need to pass this argument in to loader.discover().
getTestCaseNames
(testCaseClass)[source]¶Return a sorted sequence of method names found within testCaseClass
loadTestsFromModule
(module, use_load_tests=True)[source]¶Return a suite of all tests cases contained in the given module
loadTestsFromName
(name, module=None)[source]¶Return a suite of all tests cases given a string specifier.
The name may resolve either to a module, a test case class, a test method within a test case class, or a callable object which returns a TestCase or TestSuite instance.
The method optionally resolves the names relative to a given module.
loadTestsFromNames
(names, module=None)[source]¶Return a suite of all tests cases found using the given sequence of string specifiers. See ‘loadTestsFromName()’.
loadTestsFromTestCase
(testCaseClass)[source]¶Return a suite of all tests cases contained in testCaseClass
sortTestMethodsUsing
()¶cmp(x, y) -> integer
Return negative if x<y, zero if x==y, positive if x>y.
suiteClass
¶alias of unittest.suite.TestSuite
TextTestRunner
(stream=<open file '<stderr>', mode 'w'>, descriptions=True, verbosity=1, failfast=False, buffer=False, resultclass=None)[source]¶Custom Text tests runner to log the start and the end of a test case
resultclass
¶alias of TextTestResult
TestCase
(methodName='runTest')[source]¶TestSuite
(tests=())[source]¶A test suite is a composite test consisting of a number of TestCases.
For use, create an instance of TestSuite, then add test case instances. When all tests have been added, the suite can be passed to a test runner, such as TextTestRunner. It will run the individual test cases in the order in which they were added, aggregating the results. When subclassing, do not forget to call the base class constructor.
TestResult
(stream=None, descriptions=None, verbosity=None)[source]¶Holder for test result information.
Test results are automatically managed by the TestCase and TestSuite classes, and do not need to be explicitly manipulated by writers of tests.
Each instance holds the total number of tests run, and collections of failures and errors that occurred among those test runs. The collections contain tuples of (testcase, exceptioninfo), where exceptioninfo is the formatted traceback of the error that occurred.
addError
(*args, **kw)[source]¶Called when an error has occurred. ‘err’ is a tuple of values as returned by sys.exc_info().
addFailure
(*args, **kw)[source]¶Called when an error has occurred. ‘err’ is a tuple of values as returned by sys.exc_info().
startTestRun
()[source]¶Called once before any tests are executed.
See startTest for a method called before each test.