On Wed, Mar 7, 2018 at 11:30 AM, KCY <kevint...@hotmail.com> wrote:
> 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.

It is very unlikely this is the case, unless you are using a
handle_error() event handler that is causing this to happen.  What I
think you might be seeing is that if you're using Python 3, a Python 3
stack trace will show *both* errors, e.g. it will first indicate the
"cause", which here is the straight DBAPI error, and below that it
will say, "this exception was the direct cause of the following
exception", and then you'll see SQLAlchemy's wrapped version.   If
pytest.raises() is buggy and is attempting to unwrap the "cause", that
would be why your assertion isn't working.   I'd try replacing it
temporarily with a plain try/except and see what you get then.  Share
the complete stack trace display here as well without catching
anything.



>
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to