Review: Needs Fixing Please read the unittest.mock documentation, it has lots of examples on how to use it and the best way to do it.
https://docs.python.org/3/library/unittest.mock.html Check my comments below for the best way to use the library. Diff comments: > > === modified file 'tests/functional/openlp_plugins/bibles/test_mediaitem.py' > --- tests/functional/openlp_plugins/bibles/test_mediaitem.py 2016-06-14 > 21:55:37 +0000 > +++ tests/functional/openlp_plugins/bibles/test_mediaitem.py 2016-08-20 > 19:41:00 +0000 > @@ -150,3 +150,22 @@ > self.assertEqual(2, > self.media_item.quickSearchButton.setEnabled.call_count, 'Disable and Enable > the button') > self.assertEqual(1, self.media_item.check_search_result.call_count, > 'Check results Should had been called once') > self.assertEqual(1, self.app.set_normal_cursor.call_count, 'Normal > cursor should had been called once') > + > + def test_on_clear_button_clicked(self): > + """ > + Test that the on_clear_button_clicked works properly. (Used by Bible > search tab) > + """ > + > + # GIVEN: Mocked list_view, check_search_results & quick_search_edit. > + self.media_item.list_view = MagicMock() > + self.media_item.check_search_result = MagicMock() > + self.media_item.quick_search_edit = MagicMock() For all of the above mocks, you should be using patch.object. with patch.object(self.media_item, 'list_view') as mocked_list_view, \ patch.object(self.media_item, 'check_search_result') as mocked_check_search_result: # WHEN: ... > + > + # WHEN: on_clear_button_clicked is called > + self.media_item.on_clear_button_clicked() > + > + # THEN: Search result should be reset and search field should > receive focus. > + self.assertEqual(1, self.media_item.list_view.clear.call_count, > 'List_view.clear should had been called once.') You can actually test it with self.media_item.list_view.clear.assert_called_once_with() > + self.assertEqual(1, self.media_item.check_search_result.call_count, > 'Check results Should had been called once') Same here > + self.assertEqual(1, > self.media_item.quick_search_edit.clear.call_count, 'Should had been called > once') Same here > + self.assertEqual(1, > self.media_item.quick_search_edit.setFocus.call_count, 'Should had been > called once') Same here -- https://code.launchpad.net/~suutari-olli/openlp/fix-advanced-bible-search-clear-button-giving-focus-to-quick/+merge/303487 Your team OpenLP Core is subscribed to branch lp:openlp. _______________________________________________ Mailing list: https://launchpad.net/~openlp-core Post to : [email protected] Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp

