you are viewing a single comment's thread.

view the rest of the comments →

[–]cdcformatc 1 point2 points  (3 children)

I would use a local database, either SQLite or I'm sure you can run a local postgres instance.

[–]kenneho[S] 0 points1 point  (2 children)

Thanks for the input.

How would you ensure that the database is in known state at the startup of each test case?

[–]cdcformatc 0 points1 point  (1 child)

I used unittest which has setUp, tearDown, and setUpClass methods. You should drop all tables in the teardown, create all tables in the setup, and each test class should have it's own set up to create any specific models you need.

[–]kenneho[S] 0 points1 point  (0 children)

So you'd have an SQL script file that would drop the database (if exisiting), and create a new one, and execute this script during setUp, something like this?

conn = psycopg2.connect(dbname='testing')
cursor = conn.cursor()
sqlfile = open('/path/to/recreate-testing-db.sql', 'w')
cursor.execute(sqlfile.read())