mirror of
https://github.com/django/django.git
synced 2024-12-26 11:06:07 +00:00
Only swallow table-does-not-exist errors in tests
This commit is contained in:
parent
0bcfc068b0
commit
15c1920964
@ -20,6 +20,7 @@ class SchemaTests(TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
models = [Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagUniqueRename, UniqueTest]
|
models = [Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagUniqueRename, UniqueTest]
|
||||||
|
no_table_strings = ["no such table", "unknown table", "does not exist"]
|
||||||
|
|
||||||
# Utility functions
|
# Utility functions
|
||||||
|
|
||||||
@ -57,8 +58,11 @@ class SchemaTests(TestCase):
|
|||||||
cursor.execute(connection.schema_editor().sql_delete_table % {
|
cursor.execute(connection.schema_editor().sql_delete_table % {
|
||||||
"table": connection.ops.quote_name(field.rel.through._meta.db_table),
|
"table": connection.ops.quote_name(field.rel.through._meta.db_table),
|
||||||
})
|
})
|
||||||
except DatabaseError:
|
except DatabaseError as e:
|
||||||
connection.rollback()
|
if any([s in str(e).lower() for s in self.no_table_strings]):
|
||||||
|
connection.rollback()
|
||||||
|
else:
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
connection.commit()
|
connection.commit()
|
||||||
# Then remove the main tables
|
# Then remove the main tables
|
||||||
@ -66,8 +70,11 @@ class SchemaTests(TestCase):
|
|||||||
cursor.execute(connection.schema_editor().sql_delete_table % {
|
cursor.execute(connection.schema_editor().sql_delete_table % {
|
||||||
"table": connection.ops.quote_name(model._meta.db_table),
|
"table": connection.ops.quote_name(model._meta.db_table),
|
||||||
})
|
})
|
||||||
except DatabaseError:
|
except DatabaseError as e:
|
||||||
connection.rollback()
|
if any([s in str(e).lower() for s in self.no_table_strings]):
|
||||||
|
connection.rollback()
|
||||||
|
else:
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
connection.commit()
|
connection.commit()
|
||||||
connection.enable_constraint_checking()
|
connection.enable_constraint_checking()
|
||||||
|
Loading…
Reference in New Issue
Block a user