"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.