unittest.mock.Mock

class unittest.mock.Mock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs) Create a new Mock object. Mock takes several optional arguments that specify the behaviour of the Mock object: spec: This can be either a list of strings or an existing object (a class or instance) that acts as the specification for the mock object. If you pass in an object then a list of strings is formed by calling dir on the object (excluding unsupport

unittest.mock.MagicMock

class unittest.mock.MagicMock(*args, **kw) MagicMock is a subclass of Mock with default implementations of most of the magic methods. You can use MagicMock without having to configure the magic methods yourself. The constructor parameters have the same meaning as for Mock. If you use the spec or spec_set arguments then only magic methods that exist in the spec will be created.

unittest.mock.create_autospec()

unittest.mock.create_autospec(spec, spec_set=False, instance=False, **kwargs) Create a mock object using another object as a spec. Attributes on the mock will use the corresponding attribute on the spec object as their spec. Functions or methods being mocked will have their arguments checked to ensure that they are called with the correct signature. If spec_set is True then attempting to set attributes that don’t exist on the spec object will raise an AttributeError. If a class is used as a

unittest.mock.call.call_list()

call.call_list() For a call object that represents multiple calls, call_list() returns a list of all the intermediate calls as well as the final call.

unittest.mock.call()

unittest.mock.call(*args, **kwargs) call() is a helper object for making simpler assertions, for comparing with call_args, call_args_list, mock_calls and method_calls. call() can also be used with assert_has_calls(). >>> m = MagicMock(return_value=None) >>> m(1, 2, a='foo', b='bar') >>> m() >>> m.call_args_list == [call(1, 2, a='foo', b='bar'), call()] True

unittest.main()

unittest.main(module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=unittest.defaultTestLoader, exit=True, verbosity=1, failfast=None, catchbreak=None, buffer=None, warnings=None) A command-line program that loads a set of tests from module and runs them; this is primarily for making test modules conveniently executable. The simplest use for this function is to include the following line at the end of a test script: if __name__ == '__main__': unittest.main() You ca

unittest.installHandler()

unittest.installHandler() Install the control-c handler. When a signal.SIGINT is received (usually in response to the user pressing control-c) all registered results have stop() called.

unittest.FunctionTestCase

class unittest.FunctionTestCase(testFunc, setUp=None, tearDown=None, description=None) This class implements the portion of the TestCase interface which allows the test runner to drive the test, but does not provide the methods which test code can use to check and report errors. This is used to create test cases using legacy test code, allowing it to be integrated into a unittest-based test framework.

unittest.expectedFailure()

@unittest.expectedFailure Mark the test as an expected failure. If the test fails when run, the test is not counted as a failure.

unittest.defaultTestLoader

unittest.defaultTestLoader Instance of the TestLoader class intended to be shared. If no customization of the TestLoader is needed, this instance can be used instead of repeatedly creating new instances.