Effective PyCharm Transcripts
Chapter: Unit testing
Lecture: Concept: Coverage
0:00 Code coverage goes hand in hand with testing, it tells you do you just happen to have tests or are those tests actually testing
0:08 what's important about your program and how much So the official definition code coverage is a
0:14 measure used to describe the degree to which the source code of a program is executed
0:19 when a particular test suite runs we saw that PyCharm has fantastic support built in for a code coverage. All you have to do is go to your test file
0:29 or test folder. You want to run, go down a right click on it and you can expand this out and say run py test in test.py with coverage.
0:38 Once you already have a run configuration, you can just go up here and click the shield icon to run the test with
0:45 coverage again, remember pressing CTRL+R or whatever your run command hotkey is will not
0:50 run it with coverage. So you need to press that button or use the hotkey specifically for that option. The first time you run it may give you a warning
0:58 and say whoops you don't have coverage py or you should use the bundled one.
1:02 So I feel like a safe option is just click enable bundled coverage unless you want to make sure that coverage is included in the requirements.txt
1:09 for other people running again, it should work and you'll get to really cool things.
1:15 You'll get kind of excel like view on the right big report showing you whatever level you are navigated into your project,
1:23 what is covered. What is not covered, how much and so on but even better on the left is we have this super
1:29 cool view into the project structure and hierarchically showing us well in the projects we got 6% and unit testing we've got 66% encore.
1:38 We got 93% as you dive down. So really, really nice. This is my favorite way to just get a quick
1:44 view and then once you say want to see the details about what are the 7% of uncovered lines in core.py double click that.
1:51 And you'll end up here in the editor on the left here you'll see green sections
1:56 This is where our tests actually ran that code And possibly red sections like this one We had no test for trying to pass in a non existent table.
2:06 So the air condition never ran and line 34 was never run so we might want to write more tests. Same thing for line 37. So if we write some more tests,
2:16 the ones that check for the error conditions in particular right? The one that tries to book a non existent table or try to double book a
2:23 table. We rerun it with code coverage notice on the left here, everything is good, totally green. Now we have got 100% code coverage on 'core.py'.