Mastering PyCharm Transcripts
Chapter: Unit testing
Lecture: Concepts: Testing

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's review some of the testing concepts that we covered in this chapter.
0:04 So we started out writing tests and in our example we use pytest
0:09 we could have used any of the variety of supported testing frameworks
0:13 and here we have two tests,
0:15 notice the long method names, these are descriptions
0:17 not meant to be really used, so make them descriptive,
0:20 and these are testing the happy path,
0:23 later in our example you saw us actually test the assertions and errors as well.
0:30 Okay, so we're going to write this code but how do we run it?
0:33 Well, PyCharm has some great options for running our tests
0:37 if it's the unit test kind you can actually just right click on the file
0:42 and say run tests in this thing, it will detect that
0:44 but for the others, we need to go and create a run configuration
0:48 so over here you'll say go to Python tests
0:50 and I'd like to run say pytest, so choose the options there and set that up.
0:55 Notice also sort of there is a meta testing framework called Tox
0:59 and we can use Tox to test different versions of Python and whatnot
1:03 so this kind of is also in the realm of Python testing
1:06 but maybe not, instead of but more along with something like pytest.
1:12 Once we run our tests, you'll see down here we get some nice output,
1:15 we get a little hierarchy of the tests that are passed and the tests that failed
1:18 and if we zoom in on this a bit,
1:21 we look at the various options we have down here
1:23 so obviously we can run the test
1:25 clicking this little run button and the one in the top right
1:28 they do the same thing if the test can run configuration is the active run configuration
1:35 you can also hit CRTL R or whatever your key binding to run your project is.
1:39 Here we can hide or show the passing test,
1:44 if you have thousands and thousands of tests and only a few are failing
1:48 you want to zero in on that, so you can toggle that,
1:51 here you can toggle ignored test,
1:53 down here, this is really nice, similar to the if I have a 1000 tests
1:58 but only a few of them are failing and I want to deal with them,
2:01 this button is really nice because they will only run the tests that failed the last time,
2:05 so maybe you're running your code, there's some little bit that keeps crashing
2:08 so you can run it this way until there's no more failed ones
2:11 and then just run it again one more time to make sure everything is golden.
2:14 We also have autorun, this is pretty sweet
2:17 if you have a really nice test coverage and the tests are fast,
2:20 this will basically continually run your tests,
2:24 any time you make any changes to the code
2:27 either under test or the test code itself
2:30 it will just run in the background constantly
2:32 and just let you know the status of your application,
2:35 basically as your type, which is really pretty awesome.
2:39 Down here you can import and export results
2:42 and so if you want to save these for some reason
2:45 or pull them in and analyze them,
2:47 that's pretty cool, you can do that here.