#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, why do you want to test your code? And here I have a useful link that introduces testing in Python,
0:11 and from my own experience I think the main thing you want is to have a regression test suite. As your software grows, it becomes more complex
0:20 and you need to make sure that all the previous code keeps running. If you have a suite of tests that are fast
0:26 and you can run every time you make changes, you have a much more reliable application. Down here, what I like about this link is that
0:33 there are rules about testing, and I'll highlight a few. So every test should test one thing and be small and independent.
0:43 One test should not influence the other test. And set up and tear down, which we will see towards the end with fixtures, is a way to guarantee that.
0:52 Tests need to be fast. Your test suite will be growing, and you will run them often. You don't want slow tests to delay your development.
1:00 Testing should be automated. Again, because you run them often, it should be as hands off as possible. Fixing bugs.
1:07 If you find a bug in your application you usually want to write a test first to show that the bug, or even document the bug,
1:14 and then fix it, and then you always have that test to verify that that bug does not occur again. And there are couple of other items.
1:22 This is good link to go through when testing is really new to you. There are various frameworks in Python to facilitate you writing tests.
1:32 We have unittest, doctest, pytest, hypothesis, and tools like talks that lets you test various configurations or environments, unittest2, and mock.
1:43 In this lesson we are going to focus on my favorite, which is pytest. pytest is a framework that allows you to write test for your Python code,
1:52 and it specifies a set of rules, and it has a couple of features that really helps you write better test code. Alright, enough theory, let's move on
2:01 to the next video where I pip install pytest and pytest coverage, and we look at the example for this lesson.