i have custom exception for inserting data:
class ErrorOnInsert(BaseException):
"""Exception raised for errors in insert data to db
Attributes:
resource -- resource name
message -- explanation of the error
"""
def __init__(self, resource: str):
self.message = 'Failed to insert data for {}!'.format(resource)
super().__init__(self.message)
exception is used in this insert function to mongo:
def _add(self, data: RunnerRating):
try:
dict_data = data.as_dict()
self.collection[self.document_name].insert_one(
dict_data)
self.list_data.add(data)
except ErrorOnInsert(self.document_name) as e:
raise e
and i try to test the exception with self.repo._add(None) but it shows error something like this:
FAILED tests/integration/test_repo.py::RatingRepoTest::test_add - TypeError: catching classes that do not inherit from BaseException is not allowed