Getting started with pytest Transcripts
Chapter: Parametrization
Lecture: Combining tests without parametrization

Login or purchase this course to watch this video and the rest of the course contents.
0:00 One of the ways we can deal with these three tests being mostly the same except for a different start state is we can just combine them into one test.
0:09 So let's just go ahead and grab one of these tests and combine them into one test. So we just have test finish,
0:19 we're gonna deal with all the states and then for C. In and then we're just going to have a list of different cards.
0:28 So instead of one card here we'll do we'll start with one three.
0:39 Just three is fine and something something something we don't really care about this summary but
0:46 the we need to do and in Prog and done right the three states. And since we're listing them here we don't really need it up here.
0:57 We could grab that, delete that and move that over there. So for C. In each of these cards we'll add the card,
1:06 make it finished and do a final state of assert that it's done when it's done that works. One of the we can just we have all these the same
1:18 but since we're doing three cards we could do change them anyway just for fun. 1, 2, 3. Great. Let's see if that works. Test finish combined,
1:30 test finish combined. Well that passed doesn't tell us much and we end up with passed. Yey I have actually seen this and I've guilty of it myself a few
1:46 times of testing more than one thing. We're really testing three different test cases within one test.
1:52 What's wrong with that? I mean we're testing everything we want to write. Well, one of the things is it doesn't,
1:58 we have no documentation really of what we're testing and I really like to have the
2:03 test nodes have enough indication of what we're testing within here because there's really three test
2:08 cases and it's really only showing up with one And that's one of the problems. The other problem is if one of these fails,
2:17 like if the to do one failed or the in progress once failed, we won't finish the rest of them. So if the todo one,
2:24 if it fails right away, like let's say we just fail, this will fail all of them but it'll it won't hit all of them.
2:31 It'll just hit one so it'll stop the first time it hits it. How do I know it's the first one and not the last one.
2:38 Well I know how python works but also I can do um -l which is short for show locals and it will show me it shows C which is the card
2:49 and it says the starts the state is to do in the summary is one. So we know it's our first test case and it didn't test any of the others
2:58 So parameterization is just as easy as this but even better we'll get that next.


Talk Python's Mastodon Michael Kennedy's Mastodon