How to raise exception in a method that returns a tuple?

Viewed 105

I have the following method is_device_subscription_valid that I would like to test, when an exception has been raised.

            try:
                (
                    is_success,
                    r_nano,
                ) = await sub_service.is_device_subscription_valid(receipt.receipt)
            except (ConnectionError, OperationalError, ProtocolError):
                issues_list.append((device.id, receipt.expires_at))
    @patch("service.sub_ios_service.SubscriptionService.is_device_subscription_valid")
    async def test_invalid_premium_users(self, mock_error, client):
        mock_error.return_value.raiseError.side_effect = Mock(
            side_effect=ConnectionError("Test"), return_value=("bla", "bla")
        )
        await DailyAccessCleanup().cleanup()

However instead of raising an exception through side effects I get

>               (
                    is_success,
                    r_nano,
                ) = await sub_service.is_device_subscription_valid(receipt.receipt)
E               ValueError: not enough values to unpack (expected 2, got 0)

It shouldn't matter though what values are returned, when it should raise an exception.

Here is the proof that the method is caught by the patch, hence the path is correct.

enter image description here

0 Answers
Related