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