autospec

A unittest.mock feature that builds a mock with exactly the same methods and signatures as a real class.

In more detail

Without it a mock accepts any call, including ones the real object would reject. With it, a wrong argument list fails the test. It cannot tell you what the real object returns, so an invented return value can still lie.

Example

gateway = create_autospec(Gateway, instance=True)

Related terms

Taught in

References