mocking-utils
Highly useful utilities for mocking execution flow during unit test execution.
Quick Start
Installation
pip install mocking-utils
Usage
from mocking_utils import MockFunction
class A(object):
def my_method(self):
print('I am in my_method')
a = A()
a.my_method() # Out: 'I am in my_method'
mock = MockFunction(A, 'my_method', lambda x: print('lambda function'), call=True)
a.my_method() # Out: 'lambda function'
mock.reset()
a.my_method() # Out: 'I am in my_method'
Examples
pytest
from mocking_utils import MockFunction
@pytest.fixture(scope='module', autouse=True)
def setup__teardown():
"""
Standard setup & teardown within a module of unit tests.
"""
mocks = [
MockFunction(A, 'my_method', lambda x: print('lambda function'), call=True)
]
yield 'Setup complete'
[mock.reset() for mock in mocks]
Testing & Code Quality
Code coverage reports for master, branches, and PRs
are posted here in CodeCov.