Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: catching classes that do not inherit from BaseException is not allowed #4016

Closed
tariqjamal057 opened this issue Feb 14, 2024 · 1 comment
Labels
bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged.

Comments

@tariqjamal057
Copy link

Describe the bug

Couldn't able to write testcase for boto3 SNS exceptions.

class SNS:
    def __init__(self):
        self.client = boto3.client("sns")
        
   def create_topic(data):
       try:
           response = self.client.create_topic(**data)
       except self.client.exceptions.InvalidParameterException as e:
          raise CustomError(e)
          
          
# Testcase
class TestTopic(unittest.TestCase):
    def setUp(self):
        self.topics = SNS()
        self.mock_client = MagicMock()
        self.topics.client = self.mock_client
        self.faker = Faker()
        
    def test_create_topic_sns_exceptions(self):
        topic_data = {"topic_name": self.faker.pystr(min_chars=277, max_chars=280)}
        with mock.patch.object(self.topics.client, 'create_topic', 
        side_effect=self.topics.client.exceptions.InvalidParameterException({}, "create_topic")):
            with self.assertRaises(CustomError):
                self.topics.create_topic(topic_data)

After running the testcase getting the below error

except self.client.exceptions.InvalidParameterException as e:
TypeError: catching classes that do not inherit from BaseException is not allowed

If I directly call the create_topics with invalid data it will correctly raise the exception but for testcase doesn't work as expected

Expected Behavior

The testcase needs to be passed but it throws errors for all expections in sns.client.exceptions

Current Behavior

Reproduction Steps

Possible Solution

No response

Additional Information/Context

No response

SDK version used

boto3 1.34.41

Environment details (OS name and version, etc.)

@tariqjamal057 tariqjamal057 added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant