Django: Getting Started Transcripts
Chapter: Django ORM and Databases
Lecture: Testing Django ORM code

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Great. So how do you go about testing all this stuff? Well, Django has got your back here too. When you run the test command,
0:08 Django creates a special database for you. Just for the testing instance. Each test that gets run starts with a database transaction
0:16 which then gets rolled back after the test completes. That way, each test starts with the same state.
0:23 You wouldn't want the order of your tests to influence whether they pass or fail. The test database starts out empty.
0:30 But there are methods you can define that get run when it is set up. This is typically used to create some data common to your tests.
0:36 For example, a user to access your site. There are also tear down methods that get called afterwards in case you need to do
0:44 cleanup on some files or something. These don't get used as often. With this information in hand, let's go write some tests.


Talk Python's Mastodon Michael Kennedy's Mastodon