oslotest.mock_fixture module

class oslotest.mock_fixture.MockAutospecFixture

Bases: Fixture

A fixture to add / fix the autospec feature into the mock library.

The current version of the mock library has a few unaddressed issues, which can lead to erroneous unit tests, and can hide actual issues. This fixture is to be removed once these issues have been addressed in the mock library.

Issue addressed by the fixture:

  • mocked method’s signature checking:
    • https://github.com/testing-cabal/mock/issues/393

    • mock can only accept a spec object / class, and it makes sure that that attribute exists, but it does not check whether the given attribute is callable, or if its signature is respected in any way.

    • adds autospec argument. If the autospec argument is given, the mocked method’s signature is also checked.


Prepare the Fixture for use.

This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.

After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).


MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.



Changed in 1.3:

The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.

Changed in 1.3.1:

BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.


Replaces the mock.patch class.