Effective 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. So we started out writing tests and in our example we use pytest
0:10 we could have used any of the variety of supported testing frameworks and here we have two tests, notice the long method names, these are descriptions
0:18 not meant to be really used, so make them descriptive, and these are testing the happy path,
0:24 later in our example you saw us actually test the assertions and errors as well. Okay, so we're going to write this code but how do we run it?
0:34 Well, PyCharm has some great options for running our tests if it's the unit test kind you can actually just right click on the file
0:43 and say run tests in this thing, it will detect that but for the others, we need to go and create a run configuration
0:49 so over here you'll say go to Python tests and I'd like to run say pytest, so choose the options there and set that up.
0:56 Notice also sort of there is a meta testing framework called Tox and we can use Tox to test different versions of Python and whatnot
1:04 so this kind of is also in the realm of Python testing but maybe not, instead of but more along with something like pytest.
1:13 Once we run our tests, you'll see down here we get some nice output, we get a little hierarchy of the tests that are passed and the tests that failed
1:19 and if we zoom in on this a bit, we look at the various options we have down here so obviously we can run the test
1:26 clicking this little run button and the one in the top right they do the same thing if the test can run configuration is the active run configuration
1:36 you can also hit CRTL R or whatever your key binding to run your project is. Here we can hide or show the passing test,
1:45 if you have thousands and thousands of tests and only a few are failing you want to zero in on that, so you can toggle that,
1:52 here you can toggle ignored test, down here, this is really nice, similar to the if I have a 1000 tests
1:59 but only a few of them are failing and I want to deal with them,
2:02 this button is really nice because they will only run the tests that failed the last time,
2:06 so maybe you're running your code, there's some little bit that keeps crashing so you can run it this way until there's no more failed ones
2:12 and then just run it again one more time to make sure everything is golden. We also have autorun, this is pretty sweet
2:18 if you have a really nice test coverage and the tests are fast, this will basically continually run your tests,
2:25 any time you make any changes to the code either under test or the test code itself it will just run in the background constantly
2:33 and just let you know the status of your application, basically as your type, which is really pretty awesome.
2:40 Down here you can import and export results and so if you want to save these for some reason or pull them in and analyze them,
2:48 that's pretty cool, you can do that here.


Talk Python's Mastodon Michael Kennedy's Mastodon