In one of my tests I'm checking that a pair of (non primary) fields must be
unique. This definition is done with:
__table_args__ = (UniqueConstraint('entity_id', 'version', name=
'id_version_combined_unique'),)
where `entity_id` is an INT column referring to a foreign id and version is
a plain INT column.
The way I test for it (using pytest):
from sqlalchemy.exc import IntegrityError
def test_entity_version_entity_version_combined_unique(session_with_entities
):
# Ensure created object has duplicate data
with pytest.raises(IntegrityError):
session.add(version_conflict)
session.commit()
But the type of exceptions I get are of type sqlite3.IntegrityError or
pymysql.IntegrityError. Basically the connector's version of the error.
I couldn't find a proper super class (unless you count Exception). I
thought maybe SQLAlchemy's DBAPIError would be able to do it based on the
documentation but it didn't cut it.
Is there a proper way to catch these implementation specific exceptions?
Kind regards,
Kevin CYT
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.