Getting started with pytest Transcripts
Chapter: Parametrization
Lecture: Parametrizing functions with one parameter
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
I had went ahead in parameter is two with two parameters. The start summary and start state.
0:06
Just kind of to show you how to do two parameters and it's this list thing It needs to be basically an a list or tuple of lists or tuples
0:16
and I usually the outside there could be lists of lists or tuple of tuples It doesn't matter but I usually do a list with tupils inside just to
0:25
keep the brackets clear in my own mind. Otherwise we've got if we did tuple of tuples we'd have parens,parens,parens
0:31
at the end and that it doesn't really matter. But this is my preference. So let's take this though and simplify it a
0:38
bit because we don't really need to start the summary as we've said before. The summary change isn't really part of this test.
0:46
We're really just testing that the the state changes. So instead of passing in the start summary we can just do something again.
0:56
That's pretty easy and we can take that out and we're just doing one parameter then and we don't need the start summary.
1:04
So it's just the start state that we're parameter rising and now we don't really need a list of lists. We just need a list of things so we can just
1:14
do the to do in Prog done that all fits kinda on one line. I'm good with that and that's it.
1:27
So that's really simple right now let's compare that with our original simpler than that.
1:33
But then the the combined one that we were using combined Compare those here we got one param and the combined this does pretty much the same thing.
1:45
I think it's just as readable or or better it's I mean this this part of it's the same right now let's try to run that.
1:55
So we've got test func one program, pytest test Func one param it's three items.
2:09
And the other thing I like about this is I could parameters but a whole bunch
2:13
of stuff but in the output it's really focusing on the thing that we care about
2:18
that's different. What we really care about is that the state is different in each of these test cases for the initial start state.
2:26
And so that's what highlights it. Like let's say we we had that test in the combined one where if we
2:33
if it failed it failed one of them and didn't run the rest of them. Let's try that. Now in the parameterized version we don't need to trace back
2:43
either because it is showing us that they all failed. Each of the test cases will run even if one of them fails.
2:52
So that's really cool. We don't need them to fail though right now. We're good. That is a function parameterization
2:59
and I hopefully use it all the time because it's really powerful to get a
3:03
whole bunch of work done really fast. Oh, I wanna show something before we go just a moment.