[TIP] Foreign Key Constraint and model testing

Marcin Tustin Marcin.Tustin at dealertrack.com
Tue Sep 16 06:34:00 PDT 2014

An example of the failing test and the data/schema would be nice.

Certainly, I have never had to relax foreign key constraints when running tests. It sounds like maybe you have a problem with your fixture system?

From: testing-in-python-bounces at lists.idyll.org [mailto:testing-in-python-bounces at lists.idyll.org] On Behalf Of Sylvain Le Beux
Sent: Tuesday, September 16, 2014 8:34 AM
To: testing-in-python at lists.idyll.org
Subject: [TIP] Foreign Key Constraint and model testing

Hi all,
This is my first post and even though I have been lurking for a while into test driven development, it's been quite new that I dived into it.
The problem that caused me a great deal recently is the fact that I am doing some functional tests against a mysql database, build thanks to an sqlalchemy model.
There are of course numbers of foreign key and my I discovered that the model objects are being created only if there are no foreign key constraints on the database.
To make it more clear, I tested to run the tests with a setup where all foreign constraints are present (it is actually a dump of the database) and in another setup, the foreign key constraints are deleted, all other things being equal.
In the first configuration, the test fails and for the latter the test is a success.
Thus my interrogations :
- Is this common to delete the foreign key constraints while testing against a database model ?
- If the test fails while the foreign key constraints are present, does this means the constraints are badly implemented ?
- How do you tests the foreign key constraints themselves ?
If you have any documentation or open source projects examples that deal with these issues, I would be very glad you'd point them to me ?

Thanks in advance,


N.B. : I tried a setup where I was letting sqlalchemy build the model itself (i.e. without the dump of the current database, and it fails even sooner during the setup process, before the tests even started)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140916/95164130/attachment-0001.htm>

More information about the testing-in-python mailing list