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

[Question] How to catch an IntegrityError raised in an Entity hook? #648

Open
LaundroMat opened this issue May 21, 2022 · 0 comments
Open

Comments

@LaundroMat
Copy link

Suppose I have this model:

class Car(db.Entity):
    colour = Required(str)

    def before_insert(self):
        if self.colour != 'black':
            raise IntegrityError("You can choose any colour, as long as it's black.")

My test looks like this:

def test_create_car():
    with pytest.raises(IntegrityError) as exc_info:
        with db_session:
            Car(colour="pink")
   assert exc_info.value == "You can choose any colour, as long as it's black."

I'm having trouble finding out how I can check the error message attached to the captured IntegrityError. exc_info.value is an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant