#100DaysOfCode in Python Transcripts
Chapter: Days 10-12: Testing your code with pytest
Lecture: Concepts: what did we learn

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's review what we've learned so far.
0:04 In this lesson we used a guessing game to write pytest.
0:08 And the game went like this.
0:09 There were a maximum of 5 attempts to guess a number
0:12 and you got feedback if the number was too low or too high.
0:17 We compared pytest to unittest
0:19 and saw that it's pretty succinct.
0:23 For unittest you need a class and self-serve
0:26 equal syntax.
0:28 pytest just lets you write functions.
0:30 And this is a very simple example,
0:32 but you're already see that pytest requires far less code.
0:37 pytest has nicely formatted outputs.
0:41 For example, if a fail,
0:44 then we pass.
0:48 We saw pytest code to show how much of our code
0:51 was on our test and where tests were missing
0:54 it showed the lines in our script.
0:58 We saw mocking in action, by mocking out the building input.
1:04 Because we wanted to control what the input function
1:07 returned when playing a game.
1:10 We also saw an example of mocking out the randint() function.
1:17 We also saw how to test exceptions
1:19 with pytest, which is pretty easy.
1:21 And we saw how to get your outputs
1:23 from your program using the capfd.
1:26 And that's nice because then we can check
1:29 if the output was as expected.
1:34 And here we have a complete game,
1:37 wrapped into a test.
1:40 And then we did some TDD on Fizz Buzz,
1:46 writing tests, writing a bit of code,
1:49 writing for more tests, some more code,
1:53 some more tests
1:55 and some more code.
1:57 And notice here we used the parameterize
1:59 feature to prevent duplicating a lot of test code.
2:03 So it takes a list of typals and in the body
2:06 of the test function, I can just do one assert.
2:09 So, that's how we kept it dry.
2:15 And again, the output is very nice.
2:17 Alright, that was quite some material to take in.
2:21 I hope you are more comfortable with pytest now.
2:23 And now, it's your turn.
2:24 Keep calm and code in Python.