[SQLObject] Failing/fragile tests, and how I've worked around them.
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Andrew B. <an...@ca...> - 2005-02-02 11:12:53
|
The HEAD of SVN's tests don't pass for me out of the box. I'm testing with Postgres 7.4.6. The main issue seems to be the table setup/teardown is a bit fragile due to foreign key constraints. I have to do "dropdb test; createdb test" between test runs, and also apply this patch: Index: sqlobject/tests/test_basic.py =================================================================== --- sqlobject/tests/test_basic.py (revision 566) +++ sqlobject/tests/test_basic.py (working copy) @@ -77,8 +77,8 @@ me = StringCol(length=10) def test_foreignKey(): + setupClass(TestSO4) setupClass(TestSO3) - setupClass(TestSO4) tc3 = TestSO3(name='a') assert tc3.other is None assert tc3.other2 is None Index: sqlobject/tests/test_joins.py =================================================================== --- sqlobject/tests/test_joins.py (revision 566) +++ sqlobject/tests/test_joins.py (working copy) @@ -76,6 +76,10 @@ class TestJoin2: def setup_method(self, meth): + try: + AddressJoiner2.clearTable() + except: + pass setupClass(PersonJoiner2) setupClass(AddressJoiner2) p1 = PersonJoiner2(name='bob') The patch to test_basic.py should be completely harmless -- it just makes sure that TestS04 table is defined in the database before trying to define TestS03, which has a foreign key to it. The test_joins.py patch attempts to clear the AddressJoiner2 table if it exists, so that PersonJoiner2 can be cleared without violating any foreign key constraints. Perhaps a cleaner solution for this would be to do SET CONSTRAINTS ALL DEFERRED during the test setup, although I don't know what (if any) equivalent exists for other database backends. Finally, the unicode tests don't pass when using the "UNICODE" database encoding (as is done by "createdb -E UNICODE test"). The default encoding (whatever it is, I'm not sure) works, though. -Andrew. |