def test_mock_patch_dict(mocker: MockerFixture) -> None: """ Testing :param mock: """ x = {"original": 1} mocker.patch.dict(x, values=[("new", 10)], clear=True) assert x == {"new": 10} mocker.stopall() assert x == {"original": 1}
def test_mock_patches( mock_fs: Any, mocker: MockerFixture, check_unix_fs_mocked: Callable[[Any, Any], None], ) -> None: """ Installs mocks into `os` functions and performs a standard testing of mock functionality. We parametrize different mock methods to ensure all (intended, at least) mock API is covered. """ # mock it twice on purpose to ensure we unmock it correctly later mock_fs(mocker) mocked_rm, mocked_ls = mock_fs(mocker) check_unix_fs_mocked(mocked_rm, mocked_ls) mocker.resetall() mocker.stopall()
def test_event_handler_get_event_type(self, mocker: MockerFixture) -> None: """ Makes sure that event handler executes as expected """ # Patch validate_hasura_event mocker.patch.object(app, "get_event_type", return_value="", autospec=True) # Execute process_event, expecting an exception with pytest.raises(Exception): app.process_event(self.event_update) # Make sure it gets called app.get_event_type.assert_called_once_with(self.event_update) mocker.stopall()
def test_event_handler_validate_hasura_event( self, mocker: MockerFixture) -> None: """ Makes sure that event handler executes as expected """ mocker.patch.object(app, "validate_hasura_event", return_value=(False, dict(success="test")), autospec=True) # Execute process_event, expecting an exception with pytest.raises(Exception): app.process_event(self.event_update) # Make sure it gets called app.validate_hasura_event.assert_called_once_with(self.event_update) mocker.stopall()
def setup(mocker: MockerFixture) -> None: mocker.stopall() if "VIRTUAL_ENV" in os.environ: del os.environ["VIRTUAL_ENV"]