Getting started with pytest Transcripts
Lecture: Using keywords to select test cases
0:00 One thing to note about parameterization is that you can get a whole bunch of
0:05 tests really fast. So so far in chapter four we've got these these many files And how many tests are they? So if we just do everything so pytest,
0:18 It's 31 tests that we've generated so far. That's quite a few. Let's take a look at him.
0:26 That's a lot. So there's a we can get a lot of tests really fast now. These are all sort of testing the same thing so that's not really going
0:35 to happen in practice hopefully. But you will have different parameters for different tests.
0:40 So uh this isn't unheard of to get a whole bunch of tests with because of parameterization. If we want to just run a subset,
0:49 I want to show you another way to run a subset of tests called keywords. Before we do that, let's just talk about the other subsets we can do.
0:57 So we can do even with parameterised we can do a single test of course a test test file func
1:07 Let's do stacked stacked one. So that runs all of the ones within. Just that that not -F, -V. That file runs all those. What if I just want to run?
1:20 And I can I can still pick a test name even though it's parameterize. I can just say I want to run that paste that one function and it still
1:32 runs all the parameterizations of the function. Now. I can also just run one like let's say to do or in prog let's just grab the to do one copy.
1:47 And what happens if I just paste that? It's gonna blow up because there's no matches found. Why? Why is it doing that?
1:57 It's because these bracket things are getting mucked up within pass with the within the shell and everything. So with parameterization,
2:05 it's important to always use quotes. And now pytests will be able to find it in UNIX C type environments.
2:12 You can do either double quotes or single quotes with, if you're on windows, just use double quotes. But let's go back to our full list.
2:25 There's another way we can subset these and it's through keywords. So I can say for instance, with all of these, all the ones that do to do.
2:35 So if I I say I want to do all the all the tests that do todo, I can just say K for key word and say to do
2:44 and it'll pick all the ones that have to do in them. And then we can do how about not to do if I'm doing complex things, I need to put it in quotes,
2:52 I can say not todo and it does all the other ones, but what if I want not to do and uh,
2:59 let's see combine it with something maybe not todo and three and three picked two of them. I didn't know how many would be,
3:13 how about not todo and one of the test names and fix object, what's going on here is we have a similar thing to uh that we looked
3:26 at before with the not and and and or and parentheses. We can do parentheses too. So let's say not not to do or done And is there any that we can do?
3:44 Okay. There's I have too many quotes not to do not to do or done and fixed object. Okay. That narrowed it down.
3:53 That's a weird way to pick just that one. But as you can see, you can do kind of complex things within the keywords and its fun.