Getting started with pytest Transcripts
Chapter: Test Functions
Lecture: Running a subset of tests

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The last thing I want to show you in this chapter is how to run different ways to run a subset of tests.
0:07 So in this test classes we used test class to group some tests to just be able to run those maybe,
0:15 but we've actually done quite a few written quite a few tests right now. So let's see how many we've got. So if I go to my chapter two directory,
0:26 there's a handful of test files and if I run them all, I know there's gonna be some failures and I don't really want to see the trace
0:33 backs. So there's a flag that we're going to use now called tb equals no, to turn off trace backs and we still get this summaries,
0:43 which is nice. But really I was kind of just looking at how many failures we've got, we've got 18 tests collected test functions or methods and
0:55 13 of them passed and five failed, I'm pretty sure that we called them all.
1:01 So there's five failures, I'm pretty sure we called all of them test fail or something like that. Yeah, so all these these failed things.
1:09 So one if we want to call all the tests with fail in the name, we can say um '-k' for keyword and just say I want to find all
1:19 of the tests that have fail in the name and that will just run those. They all failed here. If we can also use the -V of
1:31 course to have them listed out there listed below here as well. So that's cool. So we can use keywords to grab a test we
1:41 want we can also directly call these test nodes, we can we can copy this whole thing and call that and or we could call
1:52 the let's do the without the fail. Let's do all of the tests with that are not failing.
1:58 And so the keyword thing, you can you can add some logic in here, you can do and's and or's and nots, so I'll do not fail all the not failed tests.
2:07 That's cool. So we can call we can use keywords with with logic in there. We can do call the test class,
2:19 we can do a test if we call just the test method we could call that or we could call the test just a test function we can use that as
2:28 to to test just that. The keywords kinda neat though. Let's do what if we wanted all the equality tests that are not failing?
2:37 so we could do equality equal and not equal and not fail. That's neat. So there's a whole bunch of options you can do with this keyword
2:52 but the combination of keywords and specifying something directly is really pretty pretty powerful to select
2:59 a subset of tests you want to run and I mean this isn't a big deal for all of our tests but for the ones we have now because if we just
3:07 you know, if we just ran everything, it really doesn't take that long. We've got 0.09 seconds. But we might have a lot of tests and we might
3:25 have tests that take a while and it does sometimes is handy to zoom in and just run a handful of tests.


Talk Python's Mastodon Michael Kennedy's Mastodon