Unittest Compatibility Layer

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.

class 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

class 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

class TestCase(methodName='runTest')[source]
assertEquals(*args, **kwargs)[source]

Fail if the two objects are unequal as determined by the ‘==’ operator.

assert_(*args, **kwargs)[source]

Check that the expression is true.

shortDescription()[source]

Returns a one-line description of the test, or None if no description has been provided.

The default implementation of this method returns the first line of the specified test method’s docstring.

class 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.

debug()[source]

Run the tests without collecting errors in a TestResult

skipIf(condition, reason)[source]

Skip a test if the condition is true.

class 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().

addExpectedFailure(test, err)[source]

Called when an expected failure/error occurred.

addFailure(*args, **kw)[source]

Called when an error has occurred. ‘err’ is a tuple of values as returned by sys.exc_info().

addSkip(test, reason)[source]

Called when a test is skipped.

addSuccess(test)[source]

Called when a test has completed successfully

addUnexpectedSuccess(*args, **kw)[source]

Called when a test was expected to fail, but succeed.

printErrors()[source]

Called by TestRunner after test run

startTest(test)[source]

Called when the given test is about to be run

startTestRun()[source]

Called once before any tests are executed.

See startTest for a method called before each test.

stop()[source]

Indicates that the tests should be aborted

stopTest(test)[source]

Called when the given test has been run

stopTestRun()[source]

Called once after all tests are executed.

See stopTest for a method called after each test.

wasSuccessful()[source]

Tells whether or not this result was a success

Previous topic

<no title>

Next topic

salttesting.xmlunit