create a table. Ensures any existing version of that table is first dropped. Also adds a cleanup rule to drop the table after the test completes.
(self, connection, tablename, ddl, cleanup=True)
| 87 | self._connections = None |
| 88 | |
| 89 | def safe_create_table(self, connection, tablename, ddl, cleanup=True): |
| 90 | """create a table. |
| 91 | |
| 92 | Ensures any existing version of that table is first dropped. |
| 93 | |
| 94 | Also adds a cleanup rule to drop the table after the test |
| 95 | completes. |
| 96 | """ |
| 97 | cursor = connection.cursor() |
| 98 | |
| 99 | with warnings.catch_warnings(): |
| 100 | warnings.simplefilter("ignore") |
| 101 | cursor.execute(f"drop table if exists `{tablename}`") |
| 102 | cursor.execute(ddl) |
| 103 | cursor.close() |
| 104 | if cleanup: |
| 105 | self.addCleanup(self.drop_table, connection, tablename) |
| 106 | |
| 107 | def drop_table(self, connection, tablename): |
| 108 | cursor = connection.cursor() |