I've got a really useful python method like this:
def stop_widget(): original_widget = load_widget_from_file() if original_widget: original_widget.close() when I want to test it to make sure I called close(), I do:
@patch('load_widget_from_file') def test_stop_widget_with_original_widget(self, lwff_mock): mock_widget = create_autospec(Widget) lwff_mock.return_value = mock_widget stop_widget() mock_widget.close.assert_called_once_with() but what do I do when I want to test not calling close when the return value of load_widget_from_file doesn't evaluate to True?
If I tried making another unit test with:
@patch('load_widget_from_file') def test_stop_widget_with_original_widget(self, lwff_mock): mock_widget = None lwff_mock.return_value = mock_widget stop_widget() mock_widget.close.assert_not_called() this would blow up.
assert_not_called?mock_widget = create_autospec(Widget)in the second method, just like in the first method?