#100DaysOfCode in Python Transcripts
Chapter: Days 10-12: Testing your code with pytest
Lecture: The importance of testing

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Before getting into the nitty gritty,
0:02 why do you want to test your code?
0:05 And here I have a useful link that introduces
0:08 testing in Python,
0:10 and from my own experience I think the main
0:12 thing you want is to have a regression test suite.
0:16 As your software grows, it becomes more complex
0:19 and you need to make sure that all the previous
0:21 code keeps running.
0:23 If you have a suite of tests that are fast
0:25 and you can run every time you make changes,
0:27 you have a much more reliable application.
0:30 Down here, what I like about this link is that
0:32 there are rules about testing,
0:35 and I'll highlight a few.
0:36 So every test should test one thing
0:39 and be small and independent.
0:42 One test should not influence the other test.
0:44 And set up and tear down,
0:46 which we will see towards the end with fixtures,
0:48 is a way to guarantee that.
0:51 Tests need to be fast.
0:52 Your test suite will be growing,
0:54 and you will run them often.
0:55 You don't want slow tests to delay your development.
0:59 Testing should be automated.
1:00 Again, because you run them often,
1:02 it should be as hands off as possible.
1:05 Fixing bugs.
1:06 If you find a bug in your application
1:08 you usually want to write a test first
1:10 to show that the bug, or even document the bug,
1:13 and then fix it, and then you always have that test
1:16 to verify that that bug does not occur again.
1:19 And there are couple of other items.
1:21 This is good link to go through when
1:23 testing is really new to you.
1:26 There are various frameworks in Python
1:28 to facilitate you writing tests.
1:31 We have unittest, doctest, pytest, hypothesis,
1:34 and tools like talks that lets you
1:37 test various configurations or environments,
1:40 unittest2, and mock.
1:42 In this lesson we are going to focus on my favorite,
1:45 which is pytest.
1:46 pytest is a framework that allows you to
1:49 write test for your Python code,
1:51 and it specifies a set of rules,
1:53 and it has a couple of features that really
1:56 helps you write better test code.
1:58 Alright, enough theory, let's move on
2:00 to the next video where I pip install pytest
2:02 and pytest coverage, and we look at
2:04 the example for this lesson.