I have switched completely to unittest.mock
and have the following working code now:
@mock.patch('.'.join([__name__, 'TestMock', 'f_3']))
@mock.patch('.'.join([__name__, 'TestMock', 'f_2']))
@mock.patch('.'.join([__name__, 'TestMock', 'f_1']))
def test_order_2(f_1: mock.NonCallableMock,
f_2: mock.NonCallableMock,
f_3: mock.NonCallableMock) -> None:
manager = mock.Mock()
manager.attach_mock(f_1, 'f_1')
manager.attach_mock(f_2, 'f_2')
manager.attach_mock(f_3, 'f_3')
obj = TestMock()
obj.run()
manager.assert_has_calls([mock.call.f_1,
mock.call.f_2,
mock.call.f_3], any_order=False)
here comes the question: I don't really understand the meaning behind attribute names so, they are mandatory, but the only reasonable names to me are the function names themselves... I have modified the attribute names as follows:
@mock.patch('.'.join([__name__, 'TestMock', 'f_3']))
@mock.patch('.'.join([__name__, 'TestMock', 'f_2']))
@mock.patch('.'.join([__name__, 'TestMock', 'f_1']))
def test_order_1(f_1: mock.NonCallableMock,
f_2: mock.NonCallableMock,
f_3: mock.NonCallableMock) -> None:
manager = mock.Mock()
manager.attach_mock(f_1, f_1._extract_mock_name())
manager.attach_mock(f_2, f_2._extract_mock_name())
manager.attach_mock(f_3, f_3._extract_mock_name())
obj = TestMock()
obj.run()
manager.assert_has_calls([mock.call.f_1,
mock.call.f_2,
mock.call.f_3], any_order=False)
would be great to hear your opinion on this!
by the way, why f_*
mock objects are of the mock.NonCallableMoc
type? I would expect they are replaced by dummy functions (Collable
)...
Thanks in advance for the help again!
Best,
Alexey