Effective PyCharm Transcripts
Chapter: Unit testing
Lecture: Concept: Testing

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's review some of the core concepts around testing, Python pytest and PyCharm. So we saw that we could write test methods that
0:09 will exercise parts of our code assert things and verify that our code is working correctly
0:14 We decided to use py tests because it's by far the most popular way to create tests in Python. Notice a couple of things the naming matters.
0:24 So the methods all start with test underscore and then they can have some huge long
0:29 descriptive name, which is really good because if you see the short report, this test Passed or, this test failed basically.
0:36 That's the description of the test. Right You never call these directly. So be generous on the names.
0:41 Also notice the name of the file table underscore test tests plural. Never mind. It contains multiple tests that needs to be singular for pytest to
0:51 discover it. And we put that file within a folder called tests and we can just right click on the test folder state run with py test boom,
0:59 off it goes. We also saw under the Python integrated tools and testing that there
1:06 are multiple frameworks we might be using if you go in at a new configuration for
1:11 a new project configuration, you run configuration basically you'll see there's actually a lot of options under this Python test section.
1:18 We also have talks. So under Python test we've got Doc test Nose test
1:23 pytest, twisted trial and unit test, 'tox' is more about setting up an environment than
1:28 maybe running py tests for that environment like Python 38 than 39 than 310 Again, if you always want to run the same framework or at least
1:36 have a default go over to the tools, then Python integrated tools, testing and then choose the one you want.
1:44 pytest or unit test is probably the most common choices here. Then we can just right click and say run pyest in a test file or
1:53 in the test directory that will create the run configuration for the default thing. Super quick and easy. Once you run it will fire up the test runner.
2:01 We've already seen the run test window throughout this course, but now we're seeing it run unit tests with a different output.
2:08 Not just the terminal output, but this hierarchical thing. Understanding the tests, we dive into it a little bit here.
2:14 We have the run tests. So rerun the tests as their selected down here. Right? You can say set up just the failing test and then click that to
2:23 rerun it and so on. Or just run the default ones. This will show passing tests. This little toggle ignored test. There's a way to say pytest.skip.
2:33 Like this might not be passing now, but let's just put it to the side and we'll come back to it. So that would show up here normally,
2:38 but you can hide those here. We can rerun the failed tests only. And then interestingly this one, this one's wild. So if you turn that on.
2:49 What this will do is anytime you make a change to files in the project,
2:53 the test files or the files under test this is probably the most important aspect of it. If you make any change and save it within a second or two
3:02 PyCharm, we'll just rerun that automatically like continuously as you type and press save it
3:07 will just keep running the test and keep running the test and keep running the test
3:10 That could be really useful if you just want to keep working and just sort
3:13 of know red green, it's a thing currently working or is it currently broken according to the test to be honest.
3:20 This is not something that I do the test take a little bit too long to run and I think it was just kind of stress me out to have those running
3:26 all the time. I run the more on demand. But if this idea appeals to you,
3:30 you just click that button and it will automatically run the test on every file,
3:34 change locally. You can export the results or import the results here and that will let you compare them or share them with someone else.
3:42 And there's other features as well. You can see the history, you can explore into the various pieces and see just
3:48 the output for that test. It's a really nice test runnerfor the PyCharm.


Talk Python's Mastodon Michael Kennedy's Mastodon