Faculty of Engineering and Mathematical Sciences 
Not logged in (login)


This forum is provided to promote discussion amongst students enrolled in Agile Web Development (CITS3403).
RSS cloud
Jump to:

Unittest permanently modifies database?

1 of 419 articles shown, currently no other people reading this forum.
From: Akhil N.
Date: Sat 23rd May, 6:09pm
"Alan Cheng"                               wrote:

> Hi, I wanted to clarify database behaviour that I'm seeing when running tests.
> I've built my files as demonstrated during last week's workshop. It seems that when I 
> register a user into the test database, then run a system test which involves dropping 
> all users in the setUp and tearDown methods, the original user is also removed. Is 
> there some way to avoid this behaviour (i.e have the database restored to original 
> state once the test finishes)? Or is this even supposed to happen in the first place?
> It seems pretty dangerous that the database is permanently modified by the tests, 
> especially if the db.dropall() is called. If someone forgets to switch from Config to 
> TestConfig, then there's a risk of losing all your data and having to revert to an 
> earlier commit or re-migrate your database.

In our case, we had a separate duplicate testing database made form the same models as the 
production/development database. You can do this changing the SQLALCHEMY_DATABASE_URI to 
have a different file name in the TESTING configuration. This way, your original database 
remains untouched during testing.

Related articles

Unittest permanently modifies database? (all 3) RSS
├─ original   Fri 22nd May, 4:30pm, Alan C.
├─ THIS   Sat 23rd May, 6:09pm, Akhil N.
└─ reply 2   Sun 24th May, 10:20am, Timothy F.
This Page

Program written by: [email protected]
Feedback welcome
Last modified:  8:27am May 24 2020